aboutsummaryrefslogtreecommitdiff
path: root/android/guava/src/com/google/common/base/MoreObjects.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava/src/com/google/common/base/MoreObjects.java')
-rw-r--r--android/guava/src/com/google/common/base/MoreObjects.java25
1 files changed, 6 insertions, 19 deletions
diff --git a/android/guava/src/com/google/common/base/MoreObjects.java b/android/guava/src/com/google/common/base/MoreObjects.java
index da9762424..033ac3aa9 100644
--- a/android/guava/src/com/google/common/base/MoreObjects.java
+++ b/android/guava/src/com/google/common/base/MoreObjects.java
@@ -58,24 +58,7 @@ public final class MoreObjects {
* @throws NullPointerException if both {@code first} and {@code second} are null
* @since 18.0 (since 3.0 as {@code Objects.firstNonNull()}).
*/
- /*
- * We annotate firstNonNull in a way that protects against NullPointerException at the cost of
- * forbidding some reasonable calls.
- *
- * The more permissive signature would be to accept (@CheckForNull T first, @CheckForNull T
- * second), since it's OK for `second` to be null as long as `first` is not also null. But we
- * expect for that flexibility to be useful relatively rarely: The more common use case is to
- * supply a clearly non-null default, like `firstNonNull(someString, "")`. And users who really
- * know that `first` is guaranteed non-null when `second` is null can write the logic out
- * longhand, including a requireNonNull call, which calls attention to the fact that the static
- * analyzer can't prove that the operation is safe.
- *
- * This matches the signature we currently have for requireNonNullElse in our own checker. (And
- * that in turn matches that method's signature under the Checker Framework.) As always, we could
- * consider the more flexible signature if we judge it worth the risks. If we do, we would likely
- * update both methods so that they continue to match.
- */
- public static <T> T firstNonNull(@CheckForNull T first, T second) {
+ public static <T> T firstNonNull(@CheckForNull T first, @CheckForNull T second) {
if (first != null) {
return first;
}
@@ -346,7 +329,7 @@ public final class MoreObjects {
}
private static boolean isEmpty(Object value) {
- // Put types estimated to be most frequent first.
+ // Put types estimated to be the most frequent first.
if (value instanceof CharSequence) {
return ((CharSequence) value).length() == 0;
} else if (value instanceof Collection) {
@@ -408,12 +391,14 @@ public final class MoreObjects {
return valueHolder;
}
+ @CanIgnoreReturnValue
private ToStringHelper addHolder(@CheckForNull Object value) {
ValueHolder valueHolder = addHolder();
valueHolder.value = value;
return this;
}
+ @CanIgnoreReturnValue
private ToStringHelper addHolder(String name, @CheckForNull Object value) {
ValueHolder valueHolder = addHolder();
valueHolder.value = value;
@@ -427,12 +412,14 @@ public final class MoreObjects {
return valueHolder;
}
+ @CanIgnoreReturnValue
private ToStringHelper addUnconditionalHolder(Object value) {
UnconditionalValueHolder valueHolder = addUnconditionalHolder();
valueHolder.value = value;
return this;
}
+ @CanIgnoreReturnValue
private ToStringHelper addUnconditionalHolder(String name, Object value) {
UnconditionalValueHolder valueHolder = addUnconditionalHolder();
valueHolder.value = value;