{
@Override
@CanIgnoreReturnValue // TODO(kevinb): remove this
@@ -66,5 +69,5 @@ public interface Function T firstNonNull(@CheckForNull T first, T second) {
* class name
* @since 18.0 (since 2.0 as {@code Objects.toStringHelper()}).
*/
- public static ToStringHelper toStringHelper(Object self) {
+ public static ToStringHelper toStringHelper(@Readonly Object self) {
return new ToStringHelper(self.getClass().getSimpleName());
}
@@ -350,7 +351,7 @@ public ToStringHelper addValue(long value) {
return addUnconditionalHolder(String.valueOf(value));
}
- private static boolean isEmpty(Object value) {
+ private static boolean isEmpty(@Readonly Object value) {
// Put types estimated to be most frequent first.
if (value instanceof CharSequence) {
return ((CharSequence) value).length() == 0;
@@ -421,13 +422,13 @@ private ValueHolder addHolder() {
return valueHolder;
}
- private ToStringHelper addHolder(@CheckForNull Object value) {
+ private ToStringHelper addHolder(@CheckForNull @Readonly Object value) {
ValueHolder valueHolder = addHolder();
valueHolder.value = value;
return this;
}
- private ToStringHelper addHolder(String name, @CheckForNull Object value) {
+ private ToStringHelper addHolder(String name, @CheckForNull @Readonly Object value) {
ValueHolder valueHolder = addHolder();
valueHolder.value = value;
valueHolder.name = checkNotNull(name);
@@ -440,13 +441,13 @@ private UnconditionalValueHolder addUnconditionalHolder() {
return valueHolder;
}
- private ToStringHelper addUnconditionalHolder(Object value) {
+ private ToStringHelper addUnconditionalHolder(@Readonly Object value) {
UnconditionalValueHolder valueHolder = addUnconditionalHolder();
valueHolder.value = value;
return this;
}
- private ToStringHelper addUnconditionalHolder(String name, Object value) {
+ private ToStringHelper addUnconditionalHolder(String name, @Readonly Object value) {
UnconditionalValueHolder valueHolder = addUnconditionalHolder();
valueHolder.value = value;
valueHolder.name = checkNotNull(name);
@@ -456,7 +457,7 @@ private ToStringHelper addUnconditionalHolder(String name, Object value) {
// Holder object for values that might be null and/or empty.
private static class ValueHolder {
@CheckForNull String name;
- @CheckForNull Object value;
+ @CheckForNull @Readonly Object value;
@CheckForNull ValueHolder next;
}
diff --git a/guava/src/com/google/common/base/Objects.java b/guava/src/com/google/common/base/Objects.java
index 13bc37f797a1..8b05a0da1ad4 100644
--- a/guava/src/com/google/common/base/Objects.java
+++ b/guava/src/com/google/common/base/Objects.java
@@ -18,6 +18,7 @@
import java.util.Arrays;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.signedness.qual.PolySigned;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -54,7 +55,7 @@ private Objects() {}
* Note for Java 7 and later: This method should be treated as deprecated; use {@link
* java.util.Objects#equals} instead.
*/
- public static boolean equal(@CheckForNull @PolySigned Object a, @CheckForNull @PolySigned Object b) {
+ public static boolean equal(@CheckForNull @PolySigned @Readonly Object a, @CheckForNull @PolySigned @Readonly Object b) {
return a == b || (a != null && a.equals(b));
}
@@ -80,7 +81,7 @@ public static boolean equal(@CheckForNull @PolySigned Object a, @CheckForNull @P
* java.util.Objects#hash} instead.
*/
@Pure
- public static int hashCode(@CheckForNull @Nullable Object... objects) {
+ public static int hashCode(@CheckForNull @Nullable @Readonly Object @Readonly ... objects) {
return Arrays.hashCode(objects);
}
}
diff --git a/guava/src/com/google/common/base/Optional.java b/guava/src/com/google/common/base/Optional.java
index 8700b4977b55..ad69f2d7e15c 100644
--- a/guava/src/com/google/common/base/Optional.java
+++ b/guava/src/com/google/common/base/Optional.java
@@ -91,6 +91,7 @@
@DoNotMock("Use Optional.of(value) or Optional.absent()")
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public abstract class Optional implements Serializable {
/**
* Returns an {@code Optional} instance with no contained reference.
diff --git a/guava/src/com/google/common/base/Preconditions.java b/guava/src/com/google/common/base/Preconditions.java
index 9205fcbee305..63655cb1813d 100644
--- a/guava/src/com/google/common/base/Preconditions.java
+++ b/guava/src/com/google/common/base/Preconditions.java
@@ -23,6 +23,7 @@
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.dataflow.qual.AssertMethod;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -151,7 +152,7 @@ public static void checkArgument(boolean expression) {
*/
@AssertMethod(IllegalArgumentException.class)
@Pure
- public static void checkArgument(boolean expression, @CheckForNull Object errorMessage) {
+ public static void checkArgument(boolean expression, @CheckForNull @Readonly Object errorMessage) {
if (!expression) {
throw new IllegalArgumentException(String.valueOf(errorMessage));
}
@@ -175,7 +176,7 @@ public static void checkArgument(boolean expression, @CheckForNull Object errorM
public static void checkArgument(
boolean expression,
String errorMessageTemplate,
- @CheckForNull @Nullable Object... errorMessageArgs) {
+ @CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (!expression) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
@@ -236,7 +237,7 @@ public static void checkArgument(boolean b, String errorMessageTemplate, long p1
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1));
}
@@ -297,7 +298,7 @@ public static void checkArgument(boolean b, String errorMessageTemplate, char p1
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, char p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, char p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -358,7 +359,7 @@ public static void checkArgument(boolean b, String errorMessageTemplate, int p1,
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, int p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, int p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -419,7 +420,7 @@ public static void checkArgument(boolean b, String errorMessageTemplate, long p1
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, long p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, long p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -435,7 +436,7 @@ public static void checkArgument(
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, char p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, char p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -451,7 +452,7 @@ public static void checkArgument(
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, int p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, int p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -467,7 +468,7 @@ public static void checkArgument(
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, long p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, long p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -483,7 +484,7 @@ public static void checkArgument(
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -501,9 +502,9 @@ public static void checkArgument(
public static void checkArgument(
boolean b,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2, p3));
}
@@ -521,10 +522,10 @@ public static void checkArgument(
public static void checkArgument(
boolean b,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3,
- @CheckForNull Object p4) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3,
+ @CheckForNull @Readonly Object p4) {
if (!b) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2, p3, p4));
}
@@ -558,7 +559,7 @@ public static void checkState(boolean expression) {
*/
@AssertMethod(IllegalStateException.class)
@Pure
- public static void checkState(boolean expression, @CheckForNull Object errorMessage) {
+ public static void checkState(boolean expression, @CheckForNull @Readonly Object errorMessage) {
if (!expression) {
throw new IllegalStateException(String.valueOf(errorMessage));
}
@@ -592,7 +593,7 @@ public static void checkState(
* that user first.
*/
@CheckForNull String errorMessageTemplate,
- @CheckForNull @Nullable Object... errorMessageArgs) {
+ @CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (!expression) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
@@ -656,7 +657,7 @@ public static void checkState(boolean b, String errorMessageTemplate, long p1) {
*/
@AssertMethod(IllegalStateException.class)
@Pure
- public static void checkState(boolean b, String errorMessageTemplate, @CheckForNull Object p1) {
+ public static void checkState(boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1));
}
@@ -721,7 +722,7 @@ public static void checkState(boolean b, String errorMessageTemplate, char p1, l
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, char p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, char p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -786,7 +787,7 @@ public static void checkState(boolean b, String errorMessageTemplate, int p1, lo
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, int p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, int p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -851,7 +852,7 @@ public static void checkState(boolean b, String errorMessageTemplate, long p1, l
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, long p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, long p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -868,7 +869,7 @@ public static void checkState(
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, char p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, char p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -885,7 +886,7 @@ public static void checkState(
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, int p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, int p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -902,7 +903,7 @@ public static void checkState(
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, long p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, long p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -919,7 +920,7 @@ public static void checkState(
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(
- boolean b, String errorMessageTemplate, @CheckForNull Object p1, @CheckForNull Object p2) {
+ boolean b, String errorMessageTemplate, @CheckForNull @Readonly Object p1, @CheckForNull @Readonly Object p2) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -938,9 +939,9 @@ public static void checkState(
public static void checkState(
boolean b,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2, p3));
}
@@ -959,10 +960,10 @@ public static void checkState(
public static void checkState(
boolean b,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3,
- @CheckForNull Object p4) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3,
+ @CheckForNull @Readonly Object p4) {
if (!b) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2, p3, p4));
}
@@ -1011,7 +1012,7 @@ public static T checkNotNull(@CheckForNull T reference) {
*/
@CanIgnoreReturnValue
@Pure
- public static T checkNotNull(@CheckForNull T reference, @CheckForNull Object errorMessage) {
+ public static T checkNotNull(@CheckForNull T reference, @CheckForNull @Readonly Object errorMessage) {
if (reference == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
@@ -1038,7 +1039,7 @@ public static T checkNotNull(@CheckForNull T reference, @CheckForNull Object
public static T checkNotNull(
@CheckForNull T reference,
String errorMessageTemplate,
- @CheckForNull @Nullable Object... errorMessageArgs) {
+ @CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (reference == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
@@ -1103,7 +1104,7 @@ public static T checkNotNull(@CheckForNull T obj, String errorMessageTemplat
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, @CheckForNull Object p1) {
+ @CheckForNull T obj, String errorMessageTemplate, @CheckForNull @Readonly Object p1) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1));
}
@@ -1171,7 +1172,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, char p1, @CheckForNull Object p2) {
+ @CheckForNull T obj, String errorMessageTemplate, char p1, @CheckForNull @Readonly Object p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1239,7 +1240,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, int p1, @CheckForNull Object p2) {
+ @CheckForNull T obj, String errorMessageTemplate, int p1, @CheckForNull @Readonly Object p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1307,7 +1308,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, long p1, @CheckForNull Object p2) {
+ @CheckForNull T obj, String errorMessageTemplate, long p1, @CheckForNull @Readonly Object p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1324,7 +1325,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, @CheckForNull Object p1, char p2) {
+ @CheckForNull T obj, String errorMessageTemplate, @CheckForNull @Readonly Object p1, char p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1341,7 +1342,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, @CheckForNull Object p1, int p2) {
+ @CheckForNull T obj, String errorMessageTemplate, @CheckForNull @Readonly Object p1, int p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1358,7 +1359,7 @@ public static T checkNotNull(
@CanIgnoreReturnValue
@Pure
public static T checkNotNull(
- @CheckForNull T obj, String errorMessageTemplate, @CheckForNull Object p1, long p2) {
+ @CheckForNull T obj, String errorMessageTemplate, @CheckForNull @Readonly Object p1, long p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1377,8 +1378,8 @@ public static T checkNotNull(
public static T checkNotNull(
@CheckForNull T obj,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2));
}
@@ -1397,9 +1398,9 @@ public static T checkNotNull(
public static T checkNotNull(
@CheckForNull T obj,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2, p3));
}
@@ -1418,10 +1419,10 @@ public static T checkNotNull(
public static T checkNotNull(
@CheckForNull T obj,
String errorMessageTemplate,
- @CheckForNull Object p1,
- @CheckForNull Object p2,
- @CheckForNull Object p3,
- @CheckForNull Object p4) {
+ @CheckForNull @Readonly Object p1,
+ @CheckForNull @Readonly Object p2,
+ @CheckForNull @Readonly Object p3,
+ @CheckForNull @Readonly Object p4) {
if (obj == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, p1, p2, p3, p4));
}
diff --git a/guava/src/com/google/common/base/Predicate.java b/guava/src/com/google/common/base/Predicate.java
index 5aa88e761687..adeda30e4b5d 100644
--- a/guava/src/com/google/common/base/Predicate.java
+++ b/guava/src/com/google/common/base/Predicate.java
@@ -18,6 +18,8 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Readonly;
+import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -43,11 +45,13 @@
* @author Kevin Bourrillion
* @since 2.0
*/
+@SuppressWarnings("pico")
@FunctionalInterface
@GwtCompatible
@AnnotatedFor({"nullness"})
@ElementTypesAreNonnullByDefault
-public interface Predicate extends java.util.function.Predicate {
+@ReceiverDependentMutable
+public interface Predicate extends java.util.function.Predicate {
/**
* Returns the result of applying this predicate to {@code input} (Java 8 users, see notes in the
* class documentation above). This method is generally expected , but not absolutely
@@ -78,7 +82,7 @@ public interface Predicate extends java.util.functio
*/
@Pure
@Override
- boolean equals(@CheckForNull Object object);
+ boolean equals(@CheckForNull @Readonly Object object);
@Override
default boolean test(@ParametricNullness T input) {
diff --git a/guava/src/com/google/common/base/Predicates.java b/guava/src/com/google/common/base/Predicates.java
index c6f219597f80..0b085cd0af9d 100644
--- a/guava/src/com/google/common/base/Predicates.java
+++ b/guava/src/com/google/common/base/Predicates.java
@@ -27,6 +27,7 @@
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -45,6 +46,7 @@
@AnnotatedFor({"nullness"})
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public final class Predicates {
private Predicates() {}
@@ -53,13 +55,13 @@ private Predicates() {}
/** Returns a predicate that always evaluates to {@code true}. */
@GwtCompatible(serializable = true)
- public static Predicate alwaysTrue() {
+ public static Predicate alwaysTrue() {
return ObjectPredicate.ALWAYS_TRUE.withNarrowedType();
}
/** Returns a predicate that always evaluates to {@code false}. */
@GwtCompatible(serializable = true)
- public static Predicate alwaysFalse() {
+ public static Predicate alwaysFalse() {
return ObjectPredicate.ALWAYS_FALSE.withNarrowedType();
}
@@ -68,7 +70,7 @@ private Predicates() {}
* null.
*/
@GwtCompatible(serializable = true)
- public static Predicate isNull() {
+ public static Predicate isNull() {
return ObjectPredicate.IS_NULL.withNarrowedType();
}
@@ -77,7 +79,7 @@ private Predicates() {}
* null.
*/
@GwtCompatible(serializable = true)
- public static Predicate notNull() {
+ public static Predicate notNull() {
return ObjectPredicate.NOT_NULL.withNarrowedType();
}
@@ -85,7 +87,7 @@ private Predicates() {}
* Returns a predicate that evaluates to {@code true} if the given predicate evaluates to {@code
* false}.
*/
- public static Predicate not(Predicate predicate) {
+ public static Predicate not(Predicate predicate) {
return new NotPredicate<>(predicate);
}
@@ -96,7 +98,7 @@ private Predicates() {}
* changes to it won't alter the behavior of this predicate. If {@code components} is empty, the
* returned predicate will always evaluate to {@code true}.
*/
- public static Predicate and(
+ public static Predicate and(
Iterable extends Predicate super T>> components) {
return new AndPredicate<>(defensiveCopy(components));
}
@@ -109,7 +111,7 @@ private Predicates() {}
* returned predicate will always evaluate to {@code true}.
*/
@SafeVarargs
- public static Predicate and(Predicate super T>... components) {
+ public static Predicate and(Predicate super T>... components) {
return new AndPredicate(defensiveCopy(components));
}
@@ -118,7 +120,7 @@ private Predicates() {}
* true}. The components are evaluated in order, and evaluation will be "short-circuited" as soon
* as a false predicate is found.
*/
- public static Predicate and(
+ public static Predicate and(
Predicate super T> first, Predicate super T> second) {
return new AndPredicate<>(Predicates.asList(checkNotNull(first), checkNotNull(second)));
}
@@ -130,7 +132,7 @@ private Predicates() {}
* changes to it won't alter the behavior of this predicate. If {@code components} is empty, the
* returned predicate will always evaluate to {@code false}.
*/
- public static Predicate or(
+ public static Predicate or(
Iterable extends Predicate super T>> components) {
return new OrPredicate<>(defensiveCopy(components));
}
@@ -143,7 +145,7 @@ private Predicates() {}
* returned predicate will always evaluate to {@code false}.
*/
@SafeVarargs
- public static Predicate or(Predicate super T>... components) {
+ public static Predicate or(Predicate super T>... components) {
return new OrPredicate(defensiveCopy(components));
}
@@ -152,7 +154,7 @@ private Predicates() {}
* {@code true}. The components are evaluated in order, and evaluation will be "short-circuited"
* as soon as a true predicate is found.
*/
- public static Predicate or(
+ public static Predicate or(
Predicate super T> first, Predicate super T> second) {
return new OrPredicate<>(Predicates.asList(checkNotNull(first), checkNotNull(second)));
}
@@ -161,7 +163,7 @@ private Predicates() {}
* Returns a predicate that evaluates to {@code true} if the object being tested {@code equals()}
* the given target or both are null.
*/
- public static Predicate equalTo(@ParametricNullness T target) {
+ public static Predicate equalTo(@ParametricNullness T target) {
return (target == null)
? Predicates.isNull()
: new IsEqualToPredicate(target).withNarrowedType();
@@ -181,7 +183,7 @@ private Predicates() {}
* instances {@code Lists.newArrayList(1)} and {@code Arrays.asList(1)}.
*/
@GwtIncompatible // Class.isInstance
- public static Predicate instanceOf(Class> clazz) {
+ public static Predicate instanceOf(Class> clazz) {
return new InstanceOfPredicate<>(clazz);
}
@@ -216,7 +218,7 @@ public static Predicate> subtypeOf(Class> clazz) {
*
* @param target the collection that may contain the function input
*/
- public static Predicate in(Collection extends T> target) {
+ public static Predicate in(Collection extends T> target) {
return new InPredicate<>(target);
}
@@ -226,7 +228,7 @@ public static Predicate> subtypeOf(Class> clazz) {
*
* @return the composition of the provided function and predicate
*/
- public static Predicate compose(
+ public static Predicate compose(
Predicate predicate, Function function) {
return new CompositionPredicate<>(predicate, function);
}
@@ -310,13 +312,13 @@ public String toString() {
};
@SuppressWarnings("unchecked") // safe contravariant cast
- Predicate withNarrowedType() {
+ Predicate withNarrowedType() {
return (Predicate) this;
}
}
/** @see Predicates#not(Predicate) */
- private static class NotPredicate
+ private static class NotPredicate
implements Predicate, Serializable {
final Predicate predicate;
@@ -355,7 +357,7 @@ public String toString() {
}
/** @see Predicates#and(Iterable) */
- private static class AndPredicate
+ private static class AndPredicate
implements Predicate, Serializable {
private final List extends Predicate super T>> components;
@@ -401,7 +403,7 @@ public String toString() {
}
/** @see Predicates#or(Iterable) */
- private static class OrPredicate
+ private static class OrPredicate
implements Predicate, Serializable {
private final List extends Predicate super T>> components;
@@ -497,14 +499,14 @@ public String toString() {
private static final long serialVersionUID = 0;
@SuppressWarnings("unchecked") // safe contravariant cast
- Predicate withNarrowedType() {
+ Predicate withNarrowedType() {
return (Predicate) this;
}
}
/** @see Predicates#instanceOf(Class) */
@GwtIncompatible // Class.isInstance
- private static class InstanceOfPredicate
+ private static class InstanceOfPredicate
implements Predicate, Serializable {
private final Class> clazz;
@@ -579,7 +581,7 @@ public String toString() {
}
/** @see Predicates#in(Collection) */
- private static class InPredicate
+ private static class InPredicate
implements Predicate, Serializable {
private final Collection> target;
@@ -622,7 +624,7 @@ public String toString() {
}
/** @see Predicates#compose(Predicate, Function) */
- private static class CompositionPredicate
+ private static class CompositionPredicate
implements Predicate , Serializable {
final Predicate p;
final Function f;
@@ -727,7 +729,7 @@ public String toString() {
private static final long serialVersionUID = 0;
}
- private static List> asList(
+ private static List> asList(
Predicate super T> first, Predicate super T> second) {
// TODO(kevinb): understand why we still get a warning despite @SafeVarargs!
return Arrays.>asList(first, second);
diff --git a/guava/src/com/google/common/base/Present.java b/guava/src/com/google/common/base/Present.java
index 60eef32d8398..282d96081620 100644
--- a/guava/src/com/google/common/base/Present.java
+++ b/guava/src/com/google/common/base/Present.java
@@ -27,6 +27,7 @@
/** Implementation of an {@link Optional} containing a reference. */
@GwtCompatible
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
final class Present extends Optional {
private final T reference;
diff --git a/guava/src/com/google/common/base/Splitter.java b/guava/src/com/google/common/base/Splitter.java
index cc606763956c..97f3fad82025 100644
--- a/guava/src/com/google/common/base/Splitter.java
+++ b/guava/src/com/google/common/base/Splitter.java
@@ -107,6 +107,7 @@
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public final class Splitter {
private final CharMatcher trimmer;
private final boolean omitEmptyStrings;
diff --git a/guava/src/com/google/common/base/Strings.java b/guava/src/com/google/common/base/Strings.java
index 7ac3abf8f2cd..9cfd7e33c852 100644
--- a/guava/src/com/google/common/base/Strings.java
+++ b/guava/src/com/google/common/base/Strings.java
@@ -28,6 +28,9 @@
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Immutable;
+import org.checkerframework.checker.pico.qual.Readonly;
+import org.checkerframework.framework.qual.AnnotatedFor;
import org.checkerframework.framework.qual.EnsuresQualifierIf;
/**
@@ -36,6 +39,7 @@
* @author Kevin Bourrillion
* @since 3.0
*/
+@AnnotatedFor("pico")
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Strings {
@@ -153,6 +157,7 @@ public static String padEnd(String string, int minLength, char padChar) {
*/
@InlineMe(replacement = "string.repeat(count)")
@InlineMeValidationDisabled("Java 11+ API only")
+ @SuppressWarnings("pico:argument.type.incompatible") // cast from @Unique @Mutable to @Immutable
public static String repeat(String string, @NonNegative int count) {
checkNotNull(string); // eager for GWT.
@@ -186,7 +191,7 @@ public static String repeat(String string, @NonNegative int count) {
*
* @since 11.0
*/
- public static String commonPrefix(CharSequence a, CharSequence b) {
+ public static String commonPrefix(@Readonly CharSequence a, @Readonly CharSequence b) {
checkNotNull(a);
checkNotNull(b);
@@ -209,7 +214,7 @@ public static String commonPrefix(CharSequence a, CharSequence b) {
*
* @since 11.0
*/
- public static String commonSuffix(CharSequence a, CharSequence b) {
+ public static String commonSuffix(@Readonly CharSequence a, @Readonly CharSequence b) {
checkNotNull(a);
checkNotNull(b);
@@ -230,7 +235,7 @@ public static String commonSuffix(CharSequence a, CharSequence b) {
* Out-of-range indexes return false.
*/
@VisibleForTesting
- static boolean validSurrogatePairAt(CharSequence string, int index) {
+ static boolean validSurrogatePairAt(@Readonly CharSequence string, int index) {
return index >= 0
&& index <= (string.length() - 2)
&& Character.isHighSurrogate(string.charAt(index))
@@ -271,11 +276,11 @@ static boolean validSurrogatePairAt(CharSequence string, int index) {
*/
// TODO(diamondm) consider using Arrays.toString() for array parameters
public static String lenientFormat(
- @CheckForNull String template, @CheckForNull @Nullable Object... args) {
+ @CheckForNull String template, @CheckForNull @Nullable @Readonly Object... args) {
template = String.valueOf(template); // null -> "null"
if (args == null) {
- args = new Object[] {"(Object[])null"};
+ args = new @Immutable Object[] {"(Object[])null"};
} else {
for (int i = 0; i < args.length; i++) {
args[i] = lenientToString(args[i]);
@@ -311,7 +316,7 @@ public static String lenientFormat(
return builder.toString();
}
- private static String lenientToString(@CheckForNull Object o) {
+ private static String lenientToString(@CheckForNull @Readonly Object o) {
if (o == null) {
return "null";
}
diff --git a/guava/src/com/google/common/base/Supplier.java b/guava/src/com/google/common/base/Supplier.java
index b0724803c200..7d2f780e2845 100644
--- a/guava/src/com/google/common/base/Supplier.java
+++ b/guava/src/com/google/common/base/Supplier.java
@@ -17,6 +17,8 @@
import com.google.common.annotations.GwtCompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.pico.qual.Readonly;
+import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
import org.checkerframework.framework.qual.AnnotatedFor;
/**
@@ -41,7 +43,9 @@
@GwtCompatible
@FunctionalInterface
@ElementTypesAreNonnullByDefault
-public interface Supplier extends java.util.function.Supplier {
+@ReceiverDependentMutable
+@SuppressWarnings("pico")
+public interface Supplier extends java.util.function.Supplier {
/**
* Retrieves an instance of the appropriate type. The returned object may or may not be a new
* instance, depending on the implementation.
diff --git a/guava/src/com/google/common/base/Suppliers.java b/guava/src/com/google/common/base/Suppliers.java
index 4b12eae90f45..5ed0f48fec12 100644
--- a/guava/src/com/google/common/base/Suppliers.java
+++ b/guava/src/com/google/common/base/Suppliers.java
@@ -40,6 +40,7 @@
@AnnotatedFor({"nullness"})
@GwtCompatible
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public final class Suppliers {
private Suppliers() {}
diff --git a/guava/src/com/google/common/base/internal/Finalizer.java b/guava/src/com/google/common/base/internal/Finalizer.java
index 574d49526506..11968cd16d75 100644
--- a/guava/src/com/google/common/base/internal/Finalizer.java
+++ b/guava/src/com/google/common/base/internal/Finalizer.java
@@ -46,6 +46,7 @@
* stop itself.
*/
@AnnotatedFor({"nullness"})
+@SuppressWarnings("pico")
// no @ElementTypesAreNonNullByDefault for the reasons discussed above
public class Finalizer implements Runnable {
diff --git a/guava/src/com/google/common/cache/AbstractLoadingCache.java b/guava/src/com/google/common/cache/AbstractLoadingCache.java
index 489597c51843..6b81ade38075 100644
--- a/guava/src/com/google/common/cache/AbstractLoadingCache.java
+++ b/guava/src/com/google/common/cache/AbstractLoadingCache.java
@@ -39,6 +39,7 @@
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public abstract class AbstractLoadingCache extends AbstractCache
implements LoadingCache {
diff --git a/guava/src/com/google/common/cache/Cache.java b/guava/src/com/google/common/cache/Cache.java
index 8755595a075d..b75d88360b84 100644
--- a/guava/src/com/google/common/cache/Cache.java
+++ b/guava/src/com/google/common/cache/Cache.java
@@ -27,6 +27,13 @@
import java.util.concurrent.ExecutionException;
import javax.annotation.CheckForNull;
+import org.checkerframework.checker.pico.qual.Immutable;
+import org.checkerframework.checker.pico.qual.Mutable;
+import org.checkerframework.checker.pico.qual.PolyMutable;
+import org.checkerframework.checker.pico.qual.Readonly;
+import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
+import org.checkerframework.framework.qual.AnnotatedFor;
+
/**
* A semi-persistent mapping from keys to values. Cache entries are manually added using {@link
* #get(Object, Callable)} or {@link #put(Object, Object)}, and are stored in the cache until either
@@ -40,10 +47,12 @@
* @author Charles Fry
* @since 10.0
*/
+@AnnotatedFor("pico")
@DoNotMock("Use CacheBuilder.newBuilder().build()")
@GwtCompatible
@ElementTypesAreNonnullByDefault
-public interface Cache {
+@ReceiverDependentMutable
+public interface Cache {
/**
* Returns the value associated with {@code key} in this cache, or {@code null} if there is no
@@ -52,7 +61,7 @@ public interface Cache {
* @since 11.0
*/
@CheckForNull
- V getIfPresent(@CompatibleWith("K") Object key);
+ V getIfPresent(@Readonly Cache this, @CompatibleWith("K") @Readonly Object key);
/**
* Returns the value associated with {@code key} in this cache, obtaining that value from {@code
@@ -100,7 +109,7 @@ public interface Cache {
* @throws ExecutionError if an error was thrown while loading the value
* @since 11.0
*/
- V get(K key, Callable extends V> loader) throws ExecutionException;
+ V get(@Readonly Cache this, K key, Callable extends V> loader) throws ExecutionException;
/**
* Returns a map of the values associated with {@code keys} in this cache. The returned map will
@@ -112,7 +121,7 @@ public interface Cache {
* extends Object> is mostly the same as > to plain Java. But to nullness checkers, they
* differ: extends Object> means "non-null types," while > means "all types."
*/
- ImmutableMap getAllPresent(Iterable extends Object> keys);
+ ImmutableMap getAllPresent(@Readonly Cache this, @Readonly Iterable extends Object> keys);
/**
* Associates {@code value} with {@code key} in this cache. If the cache previously contained a
@@ -123,7 +132,7 @@ public interface Cache {
*
* @since 11.0
*/
- void put(K key, V value);
+ void put(@Mutable Cache this, K key, V value);
/**
* Copies all of the mappings from the specified map to the cache. The effect of this call is
@@ -133,10 +142,10 @@ public interface Cache {
*
* @since 12.0
*/
- void putAll(Map extends K, ? extends V> m);
+ void putAll(@Mutable Cache this, @Readonly Map extends K, ? extends V> m);
/** Discards any cached value for key {@code key}. */
- void invalidate(@CompatibleWith("K") Object key);
+ void invalidate(@Mutable Cache this, @CompatibleWith("K") @Readonly Object key);
/**
* Discards any cached values for keys {@code keys}.
@@ -144,14 +153,14 @@ public interface Cache {
* @since 11.0
*/
// For discussion of extends Object>, see getAllPresent.
- void invalidateAll(Iterable extends Object> keys);
+ void invalidateAll(@Mutable Cache this, @Readonly Iterable extends Object> keys);
/** Discards all entries in the cache. */
- void invalidateAll();
+ void invalidateAll(@Mutable Cache this);
/** Returns the approximate number of entries in this cache. */
@CheckReturnValue
- long size();
+ long size(@Readonly Cache this);
/**
* Returns a current snapshot of this cache's cumulative statistics, or a set of default values if
@@ -165,7 +174,7 @@ public interface Cache {
*
*/
@CheckReturnValue
- CacheStats stats();
+ CacheStats stats(@Readonly Cache this);
/**
* Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to
@@ -176,11 +185,11 @@ public interface Cache {
* created, it is undefined which of the changes (if any) will be reflected in that iterator.
*/
@CheckReturnValue
- ConcurrentMap asMap();
+ @PolyMutable ConcurrentMap asMap(@PolyMutable Cache this);
/**
* Performs any pending maintenance operations needed by the cache. Exactly which activities are
* performed -- if any -- is implementation-dependent.
*/
- void cleanUp();
+ void cleanUp(@Mutable Cache this);
}
diff --git a/guava/src/com/google/common/cache/CacheBuilder.java b/guava/src/com/google/common/cache/CacheBuilder.java
index 668769b6ecfa..09c19a142218 100644
--- a/guava/src/com/google/common/cache/CacheBuilder.java
+++ b/guava/src/com/google/common/cache/CacheBuilder.java
@@ -193,6 +193,7 @@
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
+@SuppressWarnings("pico")
public final class CacheBuilder {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
diff --git a/guava/src/com/google/common/cache/CacheBuilderSpec.java b/guava/src/com/google/common/cache/CacheBuilderSpec.java
index b8447a38a001..de23b3ae976f 100644
--- a/guava/src/com/google/common/cache/CacheBuilderSpec.java
+++ b/guava/src/com/google/common/cache/CacheBuilderSpec.java
@@ -80,7 +80,7 @@
* @author Adam Winer
* @since 12.0
*/
-@SuppressWarnings("GoodTime") // lots of violations (nanosecond math)
+@SuppressWarnings({"GoodTime", "pico"}) // lots of violations (nanosecond math)
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class CacheBuilderSpec {
diff --git a/guava/src/com/google/common/cache/CacheLoader.java b/guava/src/com/google/common/cache/CacheLoader.java
index 7a5e017d03d4..ca67c3281cfd 100644
--- a/guava/src/com/google/common/cache/CacheLoader.java
+++ b/guava/src/com/google/common/cache/CacheLoader.java
@@ -56,6 +56,7 @@
* @author Charles Fry
* @since 10.0
*/
+@SuppressWarnings("pico")
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class CacheLoader {
diff --git a/guava/src/com/google/common/cache/CacheStats.java b/guava/src/com/google/common/cache/CacheStats.java
index 4ed0854314be..9509f1bc0284 100644
--- a/guava/src/com/google/common/cache/CacheStats.java
+++ b/guava/src/com/google/common/cache/CacheStats.java
@@ -24,6 +24,7 @@
import java.util.concurrent.Callable;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
+import org.checkerframework.checker.pico.qual.Immutable;
/**
* Statistics about the performance of a {@link Cache}. Instances of this class are immutable.
@@ -59,6 +60,7 @@
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
+@Immutable
public final class CacheStats {
private final long hitCount;
private final long missCount;
diff --git a/guava/src/com/google/common/cache/ForwardingCache.java b/guava/src/com/google/common/cache/ForwardingCache.java
index f118977b09a3..b0f923e5947d 100644
--- a/guava/src/com/google/common/cache/ForwardingCache.java
+++ b/guava/src/com/google/common/cache/ForwardingCache.java
@@ -24,6 +24,8 @@
import java.util.concurrent.ExecutionException;
import javax.annotation.CheckForNull;
+import org.checkerframework.checker.pico.qual.Immutable;
+
/**
* A cache which forwards all its method calls to another cache. Subclasses should override one or
* more methods to modify the behavior of the backing cache as desired per the extends ForwardingObject implements Cache {
+public abstract class ForwardingCache extends ForwardingObject implements Cache {
/** Constructor for use by subclasses. */
protected ForwardingCache() {}
@@ -120,7 +122,8 @@ public void cleanUp() {
*
* @since 10.0
*/
- public abstract static class SimpleForwardingCache extends ForwardingCache {
+
+ public abstract static class SimpleForwardingCache extends ForwardingCache {
private final Cache delegate;
protected SimpleForwardingCache(Cache delegate) {
diff --git a/guava/src/com/google/common/cache/ForwardingLoadingCache.java b/guava/src/com/google/common/cache/ForwardingLoadingCache.java
index ecd44ca8d8a9..f6da8aec6136 100644
--- a/guava/src/com/google/common/cache/ForwardingLoadingCache.java
+++ b/guava/src/com/google/common/cache/ForwardingLoadingCache.java
@@ -19,6 +19,9 @@
import com.google.common.collect.ImmutableMap;
import java.util.concurrent.ExecutionException;
+import org.checkerframework.checker.pico.qual.Immutable;
+import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
+
/**
* A cache which forwards all its method calls to another cache. Subclasses should override one or
* more methods to modify the behavior of the backing cache as desired per the extends ForwardingCache
+@ReceiverDependentMutable
+@SuppressWarnings("pico")
+public abstract class ForwardingLoadingCache extends ForwardingCache
implements LoadingCache {
/** Constructor for use by subclasses. */
@@ -72,11 +77,12 @@ public void refresh(K key) {
*
* @since 10.0
*/
- public abstract static class SimpleForwardingLoadingCache
+ @ReceiverDependentMutable
+ public abstract static class SimpleForwardingLoadingCache
extends ForwardingLoadingCache {
private final LoadingCache delegate;
- protected SimpleForwardingLoadingCache(LoadingCache delegate) {
+ protected SimpleForwardingLoadingCache(@ReceiverDependentMutable LoadingCache delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
diff --git a/guava/src/com/google/common/cache/LoadingCache.java b/guava/src/com/google/common/cache/LoadingCache.java
index e338ac4c3733..3e19c5805cd0 100644
--- a/guava/src/com/google/common/cache/LoadingCache.java
+++ b/guava/src/com/google/common/cache/LoadingCache.java
@@ -22,6 +22,13 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
+import org.checkerframework.checker.pico.qual.Immutable;
+import org.checkerframework.checker.pico.qual.Mutable;
+import org.checkerframework.checker.pico.qual.PolyMutable;
+import org.checkerframework.checker.pico.qual.Readonly;
+import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
+import org.checkerframework.framework.qual.AnnotatedFor;
+
/**
* A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and
* are stored in the cache until either evicted or manually invalidated. The common way to build
@@ -38,9 +45,11 @@
* @author Charles Fry
* @since 11.0
*/
+@AnnotatedFor("pico")
@GwtCompatible
@ElementTypesAreNonnullByDefault
-public interface LoadingCache extends Cache, Function {
+@ReceiverDependentMutable
+public interface LoadingCache extends Cache, Function {
/**
* Returns the value associated with {@code key} in this cache, first loading that value if
@@ -67,7 +76,7 @@ public interface LoadingCache extends Cache, Function {
* value
* @throws ExecutionError if an error was thrown while loading the value
*/
- V get(K key) throws ExecutionException;
+ V get(@Readonly LoadingCache this, K key) throws ExecutionException;
/**
* Returns the value associated with {@code key} in this cache, first loading that value if
@@ -93,7 +102,7 @@ public interface LoadingCache extends Cache, Function {
* explained in the last paragraph above, this should be an unchecked exception only.)
* @throws ExecutionError if an error was thrown while loading the value
*/
- V getUnchecked(K key);
+ V getUnchecked(@Readonly LoadingCache this, K key);
/**
* Returns a map of the values associated with {@code keys}, creating or retrieving those values
@@ -119,7 +128,7 @@ public interface LoadingCache extends Cache, Function {
* @throws ExecutionError if an error was thrown while loading the values
* @since 11.0
*/
- ImmutableMap getAll(Iterable extends K> keys) throws ExecutionException;
+ ImmutableMap getAll(@Readonly LoadingCache this, @Readonly Iterable extends K> keys) throws ExecutionException;
/**
* @deprecated Provided to satisfy the {@code Function} interface; use {@link #get} or {@link
@@ -130,7 +139,7 @@ public interface LoadingCache extends Cache, Function {
*/
@Deprecated
@Override
- V apply(K key);
+ V apply(@Readonly LoadingCache this, K key);
/**
* Loads a new value for {@code key}, possibly asynchronously. While the new value is loading the
@@ -150,7 +159,7 @@ public interface LoadingCache extends Cache, Function {
*
* @since 11.0
*/
- void refresh(K key);
+ void refresh(@Mutable LoadingCache this, K key);
/**
* {@inheritDoc}
@@ -159,5 +168,5 @@ public interface LoadingCache extends Cache, Function {
* cause entries to be automatically loaded.
*/
@Override
- ConcurrentMap asMap();
+ @PolyMutable ConcurrentMap asMap(@PolyMutable LoadingCache this);
}
diff --git a/guava/src/com/google/common/cache/LocalCache.java b/guava/src/com/google/common/cache/LocalCache.java
index c9462c62a5c6..cef13fd596cf 100644
--- a/guava/src/com/google/common/cache/LocalCache.java
+++ b/guava/src/com/google/common/cache/LocalCache.java
@@ -89,6 +89,8 @@
import org.checkerframework.checker.nullness.qual.KeyFor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
+import org.checkerframework.checker.pico.qual.Immutable;
+import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.signedness.qual.PolySigned;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
@@ -105,10 +107,11 @@
@SuppressWarnings({
"GoodTime", // lots of violations (nanosecond math)
"nullness", // too much trouble for the payoff
+ "pico"
})
@GwtCompatible(emulated = true)
// TODO(cpovirk): Annotate for nullness.
-class LocalCache extends AbstractMap implements ConcurrentMap {
+class LocalCache extends AbstractMap implements ConcurrentMap {
/*
* The basic strategy is to subdivide the table among Segments, each of which itself is a
@@ -403,7 +406,7 @@ Equivalence defaultEquivalence() {
},
SOFT {
@Override
- ValueReference referenceValue(
+ ValueReference referenceValue(
Segment segment, ReferenceEntry entry, V value, int weight) {
return (weight == 1)
? new SoftValueReference(segment.valueReferenceQueue, value, entry)
@@ -418,7 +421,7 @@ Equivalence defaultEquivalence() {
},
WEAK {
@Override
- ValueReference referenceValue(
+ ValueReference referenceValue(
Segment segment, ReferenceEntry entry, V value, int weight) {
return (weight == 1)
? new WeakValueReference(segment.valueReferenceQueue, value, entry)
@@ -427,13 +430,13 @@ ValueReference referenceValue(
}
@Override
- Equivalence defaultEquivalence() {
+ Equivalence<@Readonly Object> defaultEquivalence() {
return Equivalence.identity();
}
};
/** Creates a reference for the given value according to this value strength. */
- abstract ValueReference referenceValue(
+ abstract ValueReference referenceValue(
Segment segment, ReferenceEntry entry, V value, int weight);
/**
@@ -441,27 +444,27 @@ abstract ValueReference referenceValue(
* at this strength. This strategy will be used unless the user explicitly specifies an
* alternate strategy.
*/
- abstract Equivalence defaultEquivalence();
+ abstract Equivalence<@Readonly Object> defaultEquivalence();
}
/** Creates new entries. */
enum EntryFactory {
STRONG {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new StrongEntry<>(key, hash, next);
}
},
STRONG_ACCESS {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new StrongAccessEntry<>(key, hash, next);
}
@Override
- ReferenceEntry copyEntry(
+ ReferenceEntry copyEntry(
Segment segment, ReferenceEntry original, ReferenceEntry newNext) {
ReferenceEntry newEntry = super.copyEntry(segment, original, newNext);
copyAccessEntry(original, newEntry);
@@ -470,13 +473,13 @@ ReferenceEntry copyEntry(
},
STRONG_WRITE {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new StrongWriteEntry<>(key, hash, next);
}
@Override
- ReferenceEntry copyEntry(
+ ReferenceEntry copyEntry(
Segment segment, ReferenceEntry original, ReferenceEntry newNext) {
ReferenceEntry newEntry = super.copyEntry(segment, original, newNext);
copyWriteEntry(original, newEntry);
@@ -485,13 +488,13 @@ ReferenceEntry copyEntry(
},
STRONG_ACCESS_WRITE {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new StrongAccessWriteEntry<>(key, hash, next);
}
@Override
- ReferenceEntry copyEntry(
+ ReferenceEntry copyEntry(
Segment segment, ReferenceEntry original, ReferenceEntry newNext) {
ReferenceEntry newEntry = super.copyEntry(segment, original, newNext);
copyAccessEntry(original, newEntry);
@@ -501,20 +504,20 @@ ReferenceEntry copyEntry(
},
WEAK {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new WeakEntry<>(segment.keyReferenceQueue, key, hash, next);
}
},
WEAK_ACCESS {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry next) {
return new WeakAccessEntry<>(segment.keyReferenceQueue, key, hash, next);
}
@Override
- ReferenceEntry copyEntry(
+ ReferenceEntry copyEntry(
Segment segment, ReferenceEntry original, ReferenceEntry newNext) {
ReferenceEntry newEntry = super.copyEntry(segment, original, newNext);
copyAccessEntry(original, newEntry);
@@ -523,13 +526,13 @@ ReferenceEntry copyEntry(
},
WEAK_WRITE {
@Override
- ReferenceEntry newEntry(
+ ReferenceEntry newEntry(
Segment segment, K key, int hash, @Nullable ReferenceEntry