Skip to content

Commit

Permalink
Migrate from jsr305 @nullable to Checker Framework @NullableDecl.
Browse files Browse the repository at this point in the history
[]

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178274875
  • Loading branch information
cpovirk committed Dec 7, 2017
1 parent 4bd7d17 commit 6f22af4
Show file tree
Hide file tree
Showing 601 changed files with 3,539 additions and 3,407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Benchmarks for {@link ConcurrentHashMultiset}.
Expand Down Expand Up @@ -192,7 +192,7 @@ public static <E> OldConcurrentHashMultiset<E> create() {
* @return the nonnegative number of occurrences of the element
*/
@Override
public int count(@Nullable Object element) {
public int count(@NullableDecl Object element) {
try {
return unbox(countMap.get(element));
} catch (NullPointerException | ClassCastException e) {
Expand Down Expand Up @@ -295,7 +295,7 @@ public int add(E element, int occurrences) {
* @throws IllegalArgumentException if {@code occurrences} is negative
*/
@Override
public int remove(@Nullable Object element, int occurrences) {
public int remove(@NullableDecl Object element, int occurrences) {
if (occurrences == 0) {
return count(element);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ public int remove(@Nullable Object element, int occurrences) {
* @param element the element whose occurrences should all be removed
* @return the number of occurrences successfully removed, possibly zero
*/
private int removeAllOccurrences(@Nullable Object element) {
private int removeAllOccurrences(@NullableDecl Object element) {
try {
return unbox(countMap.remove(element));
} catch (NullPointerException | ClassCastException e) {
Expand All @@ -349,7 +349,7 @@ private int removeAllOccurrences(@Nullable Object element) {
* @param occurrences the number of occurrences of {@code element} to remove
* @return {@code true} if the removal was possible (including if {@code occurrences} is zero)
*/
public boolean removeExactly(@Nullable Object element, int occurrences) {
public boolean removeExactly(@NullableDecl Object element, int occurrences) {
if (occurrences == 0) {
return true;
}
Expand Down Expand Up @@ -533,7 +533,7 @@ public int hashCode() {
}

/** We use a special form of unboxing that treats null as zero. */
private static int unbox(@Nullable Integer i) {
private static int unbox(@NullableDecl Integer i) {
return (i == null) ? 0 : i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/** Benchmarks for {@link ExecutionList}. */
@VmOptions({"-Xms8g", "-Xmx8g"})
Expand Down Expand Up @@ -486,7 +486,7 @@ private static void executeListener(Runnable runnable, Executor executor) {
private static final class RunnableExecutorPair {
final Runnable runnable;
final Executor executor;
@Nullable RunnableExecutorPair next;
@NullableDecl RunnableExecutorPair next;

RunnableExecutorPair(Runnable runnable, Executor executor, RunnableExecutorPair next) {
this.runnable = runnable;
Expand Down Expand Up @@ -561,7 +561,7 @@ private static void executeListener(Runnable runnable, Executor executor) {
private static final class RunnableExecutorPair {
Runnable runnable;
Executor executor;
@Nullable RunnableExecutorPair next;
@NullableDecl RunnableExecutorPair next;

RunnableExecutorPair(Runnable runnable, Executor executor) {
this.runnable = runnable;
Expand Down Expand Up @@ -667,7 +667,7 @@ private static class RunnableExecutorPair {
final Runnable runnable;
final Executor executor;
// Volatile because this is written on one thread and read on another with no synchronization.
@Nullable volatile RunnableExecutorPair next;
@NullableDecl volatile RunnableExecutorPair next;

RunnableExecutorPair(Runnable runnable, Executor executor) {
this.runnable = runnable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.NoSuchElementException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* A bounded {@linkplain BlockingQueue blocking queue} backed by an array. This queue orders
Expand Down Expand Up @@ -388,7 +388,7 @@ public int remainingCapacity() {
* @return <tt>true</tt> if this queue changed as a result of the call
*/
@Override
public boolean remove(@Nullable Object o) {
public boolean remove(@NullableDecl Object o) {
if (o == null) return false;
final E[] items = this.items;
final Monitor monitor = this.monitor;
Expand Down Expand Up @@ -418,7 +418,7 @@ public boolean remove(@Nullable Object o) {
* @return <tt>true</tt> if this queue contains the specified element
*/
@Override
public boolean contains(@Nullable Object o) {
public boolean contains(@NullableDecl Object o) {
if (o == null) return false;
final E[] items = this.items;
final Monitor monitor = this.monitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.SortedSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* An unbounded {@linkplain BlockingQueue blocking queue} that uses the same ordering rules as class
Expand Down Expand Up @@ -124,7 +124,7 @@ public MonitorBasedPriorityBlockingQueue(int initialCapacity) {
* @throws IllegalArgumentException if <tt>initialCapacity</tt> is less than 1
*/
public MonitorBasedPriorityBlockingQueue(
int initialCapacity, @Nullable Comparator<? super E> comparator) {
int initialCapacity, @NullableDecl Comparator<? super E> comparator) {
q = new PriorityQueue<E>(initialCapacity, comparator);
}

Expand Down Expand Up @@ -303,7 +303,7 @@ public int remainingCapacity() {
* @return <tt>true</tt> if this queue changed as a result of the call
*/
@Override
public boolean remove(@Nullable Object o) {
public boolean remove(@NullableDecl Object o) {
final Monitor monitor = this.monitor;
monitor.enter();
try {
Expand All @@ -322,7 +322,7 @@ public boolean remove(@Nullable Object o) {
* @return <tt>true</tt> if this queue contains the specified element
*/
@Override
public boolean contains(@Nullable Object o) {
public boolean contains(@NullableDecl Object o) {
final Monitor monitor = this.monitor;
monitor.enter();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Helper class for creating {@link CacheBuilder} instances with all combinations of several sets of
Expand Down Expand Up @@ -120,7 +120,7 @@ public CacheBuilder<Object, Object> apply(List<Object> combination) {
private static final Function<Object, Optional<?>> NULLABLE_TO_OPTIONAL =
new Function<Object, Optional<?>>() {
@Override
public Optional<?> apply(@Nullable Object obj) {
public Optional<?> apply(@NullableDecl Object obj) {
return Optional.fromNullable(obj);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReferenceArray;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* A collection of utilities for {@link Cache} testing.
Expand Down Expand Up @@ -367,7 +367,7 @@ static void processPendingNotifications(Cache<?, ?> cache) {
}

interface Receiver<T> {
void accept(@Nullable T object);
void accept(@NullableDecl T object);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Utility {@link CacheLoader} implementations intended for use in testing.
Expand Down Expand Up @@ -57,7 +57,7 @@ public Map<K, V> loadAll(Iterable<? extends K> keys) throws Exception {
}

/** Returns a {@link CacheLoader} that returns the given {@code constant} for every request. */
static <K, V> ConstantLoader<K, V> constantLoader(@Nullable V constant) {
static <K, V> ConstantLoader<K, V> constantLoader(@NullableDecl V constant) {
return new ConstantLoader<>(constant);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Unit test for {@link FluentIterable}.
Expand Down Expand Up @@ -850,7 +850,7 @@ public void testUniqueIndex_nullValue() {
.uniqueIndex(
new Function<Integer, Object>() {
@Override
public Object apply(@Nullable Integer input) {
public Object apply(@NullableDecl Integer input) {
return String.valueOf(input);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
import javax.annotation.Nullable;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Tests for {@link ForwardingSortedMultiset}.
Expand Down Expand Up @@ -93,12 +93,12 @@ public SortedMultiset<E> subMultiset(
}

@Override
public int count(@Nullable Object element) {
public int count(@NullableDecl Object element) {
return standardCount(element);
}

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

Expand All @@ -123,7 +123,7 @@ public void clear() {
}

@Override
public boolean contains(@Nullable Object object) {
public boolean contains(@NullableDecl Object object) {
return standardContains(object);
}

Expand All @@ -143,7 +143,7 @@ public Iterator<E> iterator() {
}

@Override
public boolean remove(@Nullable Object object) {
public boolean remove(@NullableDecl Object object) {
return standardRemove(object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import javax.annotation.Nullable;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Test suites for wrappers in {@code Maps}.
Expand Down Expand Up @@ -561,15 +561,15 @@ static void putEntries(Map<String, String> map, Entry<String, String>[] entries)
static final Predicate<String> FILTER_KEYS =
new Predicate<String>() {
@Override
public boolean apply(@Nullable String string) {
public boolean apply(@NullableDecl String string) {
return !"banana".equals(string) && !"eggplant".equals(string);
}
};

static final Predicate<String> FILTER_VALUES =
new Predicate<String>() {
@Override
public boolean apply(@Nullable String string) {
public boolean apply(@NullableDecl String string) {
return !"toast".equals(string) && !"spam".equals(string);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Tests for {@link Maps#transformValues}.
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testTransformEqualityOfMapsWithNullValues() {
underlying,
new Function<String, Boolean>() {
@Override
public Boolean apply(@Nullable String from) {
public Boolean apply(@NullableDecl String from) {
return from == null;
}
});
Expand Down Expand Up @@ -274,7 +274,7 @@ public void testTransformEntrySetContains() {
underlying,
new Function<Boolean, Boolean>() {
@Override
public Boolean apply(@Nullable Boolean from) {
public Boolean apply(@NullableDecl Boolean from) {
return (from == null) ? true : null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Tests for {@link Maps#transformValues} when the backing map's views have iterators that don't
Expand Down Expand Up @@ -232,7 +232,7 @@ public void testTransformEqualityOfMapsWithNullValues() {
underlying,
new Function<String, Boolean>() {
@Override
public Boolean apply(@Nullable String from) {
public Boolean apply(@NullableDecl String from) {
return from == null;
}
});
Expand Down Expand Up @@ -350,7 +350,7 @@ public void testTransformEntrySetContains() {
underlying,
new Function<Boolean, Boolean>() {
@Override
public Boolean apply(@Nullable Boolean from) {
public Boolean apply(@NullableDecl Boolean from) {
return (from == null) ? true : null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.annotation.Nullable;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Unit test for {@code Multimaps}.
Expand Down Expand Up @@ -266,8 +266,8 @@ private static void checkUnmodifiableMultimap(
private static void checkUnmodifiableMultimap(
Multimap<String, Integer> multimap,
boolean permitsDuplicates,
@Nullable String nullKey,
@Nullable Integer nullValue) {
@NullableDecl String nullKey,
@NullableDecl Integer nullValue) {
Multimap<String, Integer> unmodifiable =
prepareUnmodifiableTests(multimap, permitsDuplicates, nullKey, nullValue);

Expand Down Expand Up @@ -296,8 +296,8 @@ private static void checkUnmodifiableMultimap(
private static Multimap<String, Integer> prepareUnmodifiableTests(
Multimap<String, Integer> multimap,
boolean permitsDuplicates,
@Nullable String nullKey,
@Nullable Integer nullValue) {
@NullableDecl String nullKey,
@NullableDecl Integer nullValue) {
multimap.clear();
multimap.put("foo", 1);
multimap.put("foo", 2);
Expand Down

0 comments on commit 6f22af4

Please sign in to comment.