Skip to content

Commit

Permalink
Use the type annotation version of @nullable in the Java 8 branch
Browse files Browse the repository at this point in the history
RELNOTES=Use the type annotation version of @nullable in the Java 8 branch

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195842620
  • Loading branch information
cushon authored and ronshapiro committed May 9, 2018
1 parent d9113d5 commit 0a2258e
Show file tree
Hide file tree
Showing 334 changed files with 1,947 additions and 2,012 deletions.
Expand Up @@ -767,7 +767,7 @@ private static <T> T invoke(Invokable<?, ? extends T> factory, List<?> args)
T returnValue = factory.invoke(null, args.toArray());
if (returnValue == null) {
Assert.assertTrue(
factory + " returns null but it's not annotated with @NullableDecl", isNullable(factory));
factory + " returns null but it's not annotated with @Nullable", isNullable(factory));
}
return returnValue;
}
Expand Down
Expand Up @@ -52,9 +52,8 @@
/**
* A test utility that verifies that your methods and constructors throw {@link
* NullPointerException} or {@link UnsupportedOperationException} whenever null is passed to a
* parameter that isn't annotated with {@link javax.annotation.Nullable}, {@link
* javax.annotation.CheckForNull}, or {@link
* org.checkerframework.checker.nullness.compatqual.NullableDecl}.
* parameter that isn't annotated with an annotation with the simple name {@code Nullable}, {@lcode
* CheckForNull}, {@link NullableType}, or {@link NullableDecl}.
*
* <p>The tested methods and constructors are invoked -- each time with one parameter being null and
* the rest not null -- and the test fails if no expected exception is thrown. {@code
Expand Down
Expand Up @@ -477,7 +477,7 @@ public void testInstantiate_factoryMethodReturnsNullButNotAnnotated() throws Exc
try {
tester.instantiate(FactoryMethodReturnsNullButNotAnnotated.class);
} catch (AssertionFailedError expected) {
assertThat(expected.getMessage()).contains("@NullableDecl");
assertThat(expected.getMessage()).contains("@Nullable");
return;
}
fail("should have failed");
Expand Down
Expand Up @@ -85,8 +85,7 @@ public static void staticOneArgCheckForNullCorrectlyDoesNotThrowNPE(
// null? no problem
}

public static void staticOneArgJsr305NullableCorrectlyDoesNotThrowNPE(
@javax.annotation.Nullable String s) {
public static void staticOneArgJsr305NullableCorrectlyDoesNotThrowNPE(@NullableDecl String s) {
// null? no problem
}

Expand Down Expand Up @@ -498,7 +497,7 @@ public void twoMixedArgsThrows(@NullableDecl Integer i, String s) {
doThrow(i);
}

public void twoNullableArgs(@NullableDecl String s, @javax.annotation.Nullable Integer i) {}
public void twoNullableArgs(@NullableDecl String s, @NullableDecl Integer i) {}

public void twoNullableArgsThrowsFirstArg(@NullableDecl String s, @NullableDecl Integer i) {
doThrow(s);
Expand Down
Expand Up @@ -675,7 +675,7 @@ public void clear() {
* <p>The returned list is not serializable and does not have random access.
*/
@Override
public List<V> get(final @NullableDecl K key) {
public List<V> get(@NullableDecl final K key) {
return new AbstractSequentialList<V>() {
@Override
public int size() {
Expand Down
Expand Up @@ -14,11 +14,11 @@

package com.google.common.base;

import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Holder for extra methods of {@code Objects} only in web. */
abstract class ExtraObjectsMethodsForWeb {
public static boolean equal(@NullableDecl String a, @NullableDecl String b) {
public static boolean equal(@Nullable String a, @Nullable String b) {
return a == b;
}
}
Expand Up @@ -21,7 +21,7 @@
import java.util.concurrent.TimeUnit;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/** @author Jesse Wilson */
final class Platform {
Expand Down Expand Up @@ -52,17 +52,17 @@ static String formatCompact4Digits(double value) {
}

@JsMethod
static native boolean stringIsNullOrEmpty(@NullableDecl String string) /*-{
static native boolean stringIsNullOrEmpty(@Nullable String string) /*-{
return !string;
}-*/;

@JsMethod
static native String nullToEmpty(@NullableDecl String string) /*-{
static native String nullToEmpty(@Nullable String string) /*-{
return string || "";
}-*/;

@JsMethod
static native String emptyToNull(@NullableDecl String string) /*-{
static native String emptyToNull(@Nullable String string) /*-{
return string || null;
}-*/;

Expand Down
Expand Up @@ -39,7 +39,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* LocalCache emulation for GWT.
Expand Down Expand Up @@ -375,7 +375,7 @@ public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException
}

@Override
@NullableDecl
@Nullable
public V getIfPresent(Object key) {
return localCache.getIfPresent(key);
}
Expand Down Expand Up @@ -476,7 +476,7 @@ public CapacityEnforcingLinkedHashMap(
boolean accessOrder,
long maximumSize,
StatsCounter statsCounter,
@NullableDecl RemovalListener removalListener) {
@Nullable RemovalListener removalListener) {
super(initialCapacity, loadFactor, accessOrder);
this.maximumSize = maximumSize;
this.statsCounter = statsCounter;
Expand Down Expand Up @@ -682,7 +682,7 @@ public V getValue() {
}

@Override
public boolean equals(@NullableDecl Object object) {
public boolean equals(@Nullable Object object) {
// Cannot use key and value equivalence
if (object instanceof Entry) {
Entry<?, ?> that = (Entry<?, ?>) object;
Expand Down
Expand Up @@ -20,7 +20,7 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.SortedSet;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* This class provides a skeletal implementation of the {@link SortedMultiset} interface.
Expand Down Expand Up @@ -98,9 +98,9 @@ public Entry<E> pollLastEntry() {

@Override
public SortedMultiset<E> subMultiset(
@NullableDecl E fromElement,
@Nullable E fromElement,
BoundType fromBoundType,
@NullableDecl E toElement,
@Nullable E toElement,
BoundType toBoundType) {
// These are checked elsewhere, but NullPointerTester wants them checked eagerly.
checkNotNull(fromBoundType);
Expand Down
Expand Up @@ -17,7 +17,7 @@
package com.google.common.collect;

import java.util.Collection;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A GWT-only class only used by GWT emulations. It is used to consolidate the definitions of method
Expand All @@ -40,7 +40,7 @@ public UnmodifiableIterator<E> iterator() {
}

@Override
public boolean contains(@NullableDecl Object object) {
public boolean contains(@Nullable Object object) {
return object != null && delegate.contains(object);
}

Expand Down
Expand Up @@ -18,7 +18,7 @@

import java.util.Collection;
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT emulated version of {@link ImmutableList}. TODO(cpovirk): more doc
Expand All @@ -31,11 +31,11 @@ abstract class ForwardingImmutableList<E> extends ImmutableList<E> {

abstract List<E> delegateList();

public int indexOf(@NullableDecl Object object) {
public int indexOf(@Nullable Object object) {
return delegateList().indexOf(object);
}

public int lastIndexOf(@NullableDecl Object object) {
public int lastIndexOf(@Nullable Object object) {
return delegateList().lastIndexOf(object);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ public UnmodifiableIterator<E> iterator() {
}

@Override
public boolean contains(@NullableDecl Object object) {
public boolean contains(@Nullable Object object) {
return object != null && delegateList().contains(object);
}

Expand Down
Expand Up @@ -21,7 +21,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT implementation of {@link ImmutableMap} that forwards to another map.
Expand Down Expand Up @@ -57,15 +57,15 @@ public final boolean isEmpty() {
return delegate.isEmpty();
}

public final boolean containsKey(@NullableDecl Object key) {
public final boolean containsKey(@Nullable Object key) {
return Maps.safeContainsKey(delegate, key);
}

public final boolean containsValue(@NullableDecl Object value) {
public final boolean containsValue(@Nullable Object value) {
return delegate.containsValue(value);
}

public V get(@NullableDecl Object key) {
public V get(@Nullable Object key) {
return (key == null) ? null : Maps.safeGet(delegate, key);
}

Expand Down Expand Up @@ -119,7 +119,7 @@ public int size() {
}

@Override
public boolean equals(@NullableDecl Object object) {
public boolean equals(@Nullable Object object) {
return delegate.equals(object);
}

Expand Down
Expand Up @@ -19,7 +19,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT implementation of {@link ImmutableSet} that forwards to another {@code Set} implementation.
Expand All @@ -41,7 +41,7 @@ public UnmodifiableIterator<E> iterator() {
}

@Override
public boolean contains(@NullableDecl Object object) {
public boolean contains(@Nullable Object object) {
return object != null && delegate.contains(object);
}

Expand Down
Expand Up @@ -24,7 +24,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Spliterator;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT emulated version of {@link ImmutableCollection}.
Expand All @@ -43,7 +43,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple

public abstract UnmodifiableIterator<E> iterator();

public boolean contains(@NullableDecl Object object) {
public boolean contains(@Nullable Object object) {
return object != null && super.contains(object);
}

Expand Down
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.RandomAccess;
import java.util.stream.Collector;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT emulated version of {@link com.google.common.collect.ImmutableList}. TODO(cpovirk): more doc
Expand Down Expand Up @@ -216,12 +216,12 @@ private static <E> List<E> nullCheckedList(Object... array) {
}

@Override
public int indexOf(@NullableDecl Object object) {
public int indexOf(@Nullable Object object) {
return (object == null) ? -1 : Lists.indexOfImpl(this, object);
}

@Override
public int lastIndexOf(@NullableDecl Object object) {
public int lastIndexOf(@Nullable Object object) {
return (object == null) ? -1 : Lists.lastIndexOfImpl(this, object);
}

Expand Down Expand Up @@ -272,7 +272,7 @@ public ImmutableList<E> asList() {
}

@Override
public boolean equals(@NullableDecl Object obj) {
public boolean equals(@Nullable Object obj) {
return Lists.equalsImpl(this, obj);
}

Expand Down
Expand Up @@ -37,7 +37,7 @@
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT emulation of {@link com.google.common.collect.ImmutableMap}. For non sorted maps, it is a
Expand Down Expand Up @@ -283,12 +283,12 @@ public boolean isEmpty() {
}

@Override
public boolean containsKey(@NullableDecl Object key) {
public boolean containsKey(@Nullable Object key) {
return get(key) != null;
}

@Override
public boolean containsValue(@NullableDecl Object value) {
public boolean containsValue(@Nullable Object value) {
return values().contains(value);
}

Expand Down Expand Up @@ -368,12 +368,12 @@ public ImmutableSet<K> keySet() {
}

@Override
public boolean containsKey(@NullableDecl Object key) {
public boolean containsKey(@Nullable Object key) {
return ImmutableMap.this.containsKey(key);
}

@Override
public ImmutableSet<V> get(@NullableDecl Object key) {
public ImmutableSet<V> get(@Nullable Object key) {
V outerValue = ImmutableMap.this.get(key);
return (outerValue == null) ? null : ImmutableSet.of(outerValue);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ ImmutableCollection<V> createValues() {
}

@Override
public boolean equals(@NullableDecl Object object) {
public boolean equals(@Nullable Object object) {
return Maps.equalsImpl(this, object);
}

Expand Down
Expand Up @@ -29,7 +29,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collector;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* GWT emulation of {@link com.google.common.collect.ImmutableSortedSet}.
Expand Down Expand Up @@ -270,7 +270,7 @@ public <T> T[] toArray(T[] other) {
}

@Override
public boolean contains(@NullableDecl Object object) {
public boolean contains(@Nullable Object object) {
try {
// This set never contains null. We need to explicitly check here
// because some comparator might throw NPE (e.g. the natural ordering).
Expand Down

0 comments on commit 0a2258e

Please sign in to comment.