Skip to content

Commit

Permalink
Upgrade error-prone and pmd static analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed May 31, 2020
1 parent 4451d44 commit 56b3124
Show file tree
Hide file tree
Showing 50 changed files with 194 additions and 228 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ build
build-cache
test-output
jitwatch.out
.java-version
.DS_Store
.classpath
.settings
Expand Down
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.8
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class LocalCacheRule implements Consumer<LocalCacheContext> {
protected LocalCacheContext context;

@SuppressWarnings({"NullAway.Init", "PMD.UnnecessaryConstructor"})
public LocalCacheRule() {}
LocalCacheRule() {}

@Override
public void accept(LocalCacheContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class NodeRule implements Consumer<NodeContext> {
protected NodeContext context;

@SuppressWarnings("NullAway.Init")
public NodeRule() {}
NodeRule() {}

@Override
public final void accept(NodeContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static final class Timer extends Node<Integer, Integer> {
static final class MockCache extends BoundedLocalCache<Integer, Integer> {

@SuppressWarnings({"unchecked", "rawtypes"})
protected MockCache() {
MockCache() {
super((Caffeine) Caffeine.newBuilder(), /* cacheLoader */ null, /* isAsync */ false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public final class SingleConsumerQueueProfiler extends ProfilerHook {
final AtomicBoolean consumer = new AtomicBoolean();
final Queue<Boolean> queue = queueType.create();

SingleConsumerQueueProfiler() {
ProfilerHook.NUM_THREADS = 8;
}

@Override
protected void profile() {
if (consumer.compareAndSet(false, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -235,7 +234,7 @@ public void accept(@Nullable Map<K, V> result, @Nullable Throwable error) {
if (error == null) {
error = new NullMapCompletionException();
}
for (Entry<K, CompletableFuture<V>> entry : proxies.entrySet()) {
for (Map.Entry<K, CompletableFuture<V>> entry : proxies.entrySet()) {
cache.remove(entry.getKey(), entry.getValue());
entry.getValue().obtrudeException(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class MpscGrowableArrayQueue<E> extends MpscChunkedArrayQueue<E> {
* be the upper limit of number of elements in this queue. Must be 4 or more and round up
* to a larger power of 2 than initialCapacity.
*/
public MpscGrowableArrayQueue(int initialCapacity, int maxCapacity) {
MpscGrowableArrayQueue(int initialCapacity, int maxCapacity) {
super(initialCapacity, maxCapacity);
}

Expand All @@ -69,7 +69,7 @@ abstract class MpscChunkedArrayQueue<E> extends MpscChunkedArrayQueueColdProduce
long p0, p1, p2, p3, p4, p5, p6, p7;
long p10, p11, p12, p13, p14, p15, p16, p17;

public MpscChunkedArrayQueue(int initialCapacity, int maxCapacity) {
MpscChunkedArrayQueue(int initialCapacity, int maxCapacity) {
super(initialCapacity, maxCapacity);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ protected long getCurrentBufferCapacity(long mask) {
abstract class MpscChunkedArrayQueueColdProducerFields<E> extends BaseMpscLinkedArrayQueue<E> {
protected final long maxQueueCapacity;

public MpscChunkedArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) {
MpscChunkedArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) {
super(initialCapacity);
if (maxCapacity < 4) {
throw new IllegalArgumentException("Max capacity must be 4 or more");
Expand Down Expand Up @@ -184,7 +184,7 @@ abstract class BaseMpscLinkedArrayQueue<E> extends BaseMpscLinkedArrayQueueColdP
* @param initialCapacity the queue initial capacity. If chunk size is fixed this will be the
* chunk size. Must be 2 or more.
*/
public BaseMpscLinkedArrayQueue(final int initialCapacity) {
BaseMpscLinkedArrayQueue(final int initialCapacity) {
if (initialCapacity < 2) {
throw new IllegalArgumentException("Initial capacity must be 2 or more");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public long missCount() {
* Note that {@code hitRate + missRate =~ 1.0}. Cache misses include all requests which
* weren't cache hits, including requests which resulted in either successful or failed loading
* attempts, and requests which waited for other threads to finish loading. It is thus the case
* that {@code missCount &gt;= loadSuccessCount + loadFailureCount}. Multiple
* that {@code missCount >= loadSuccessCount + loadFailureCount}. Multiple
* concurrent misses for the same key will result in a single load operation.
*
* @return the ratio of cache requests which were misses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void contains_whenNotFound(Queue<Integer> queue) {
assertThat(queue.contains(-1), is(false));
}

@SuppressWarnings("ReturnValueIgnored")
@Test(dataProvider = "empty", expectedExceptions = NullPointerException.class)
public void containsAll_withNull(Queue<?> queue) {
queue.containsAll(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Spliterator;
Expand Down Expand Up @@ -139,6 +138,7 @@ public void clear_writerFails(Map<Integer, Integer> map, CacheContext context) {
/* --------------- contains --------------- */

@CheckNoWriter @CheckNoStats
@SuppressWarnings("ReturnValueIgnored")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void containsKey_null(Map<Integer, Integer> map, CacheContext context) {
Expand All @@ -163,6 +163,7 @@ public void containsKey_absent(Map<Integer, Integer> map, CacheContext context)
}

@CheckNoWriter @CheckNoStats
@SuppressWarnings("ReturnValueIgnored")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void containsValue_null(Map<Integer, Integer> map, CacheContext context) {
Expand Down Expand Up @@ -1894,7 +1895,7 @@ public void valueSpliterator_estimateSize(Map<Integer, Integer> map, CacheContex
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void entrySetToArray_null(Map<Integer, Integer> map, CacheContext context) {
map.entrySet().toArray((Entry<?, ?>[]) null);
map.entrySet().toArray((Map.Entry<?, ?>[]) null);
}

@CheckNoWriter @CheckNoStats
Expand Down Expand Up @@ -1968,7 +1969,7 @@ public void entrySet_removeIf_null(Map<Integer, Integer> map, CacheContext conte
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySet_removeIf(Map<Integer, Integer> map, CacheContext context) {
Predicate<Entry<Integer, Integer>> isEven = entry -> (entry.getValue() % 2) == 0;
Predicate<Map.Entry<Integer, Integer>> isEven = entry -> (entry.getValue() % 2) == 0;
boolean hasEven = map.entrySet().stream().anyMatch(isEven);

boolean removedIfEven = map.entrySet().removeIf(isEven);
Expand All @@ -1983,7 +1984,7 @@ public void entrySet_removeIf(Map<Integer, Integer> map, CacheContext context) {
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySet(Map<Integer, Integer> map, CacheContext context) {
Set<Entry<Integer, Integer>> entries = map.entrySet();
Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
assertThat(entries.contains(new Object()), is(false));
assertThat(entries.remove(new Object()), is(false));
assertThat(entries, hasSize(context.original().size()));
Expand All @@ -2005,8 +2006,8 @@ public void entrySet(Map<Integer, Integer> map, CacheContext context) {
@Test(dataProvider = "caches")
public void entryIterator(Map<Integer, Integer> map, CacheContext context) {
int iterations = 0;
for (Iterator<Entry<Integer, Integer>> i = map.entrySet().iterator(); i.hasNext();) {
Entry<Integer, Integer> entry = i.next();
for (Iterator<Map.Entry<Integer, Integer>> i = map.entrySet().iterator(); i.hasNext();) {
Map.Entry<Integer, Integer> entry = i.next();
assertThat(map, hasEntry(entry.getKey(), entry.getValue()));
iterations++;
i.remove();
Expand Down Expand Up @@ -2041,7 +2042,7 @@ public void entryIterator_noMoreElements(Map<Integer, Integer> map, CacheContext
compute = Compute.SYNC, writer = Writer.EXCEPTIONAL, removalListener = Listener.REJECTING)
public void entryIterator_writerFails(Map<Integer, Integer> map, CacheContext context) {
try {
Iterator<Entry<Integer, Integer>> i = map.entrySet().iterator();
Iterator<Map.Entry<Integer, Integer>> i = map.entrySet().iterator();
i.next();
i.remove();
} finally {
Expand Down Expand Up @@ -2085,7 +2086,7 @@ public void entrySpliterator_tryAdvance_null(
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void entrySpliterator_tryAdvance(Map<Integer, Integer> map, CacheContext context) {
Spliterator<Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
Spliterator<Map.Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
int[] count = new int[1];
boolean advanced;
do {
Expand All @@ -2103,8 +2104,8 @@ public void entrySpliterator_tryAdvance(Map<Integer, Integer> map, CacheContext
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void entrySpliterator_trySplit(Map<Integer, Integer> map, CacheContext context) {
Spliterator<Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
Spliterator<Entry<Integer, Integer>> other = MoreObjects.firstNonNull(
Spliterator<Map.Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
Spliterator<Map.Entry<Integer, Integer>> other = MoreObjects.firstNonNull(
spliterator.trySplit(), Spliterators.emptySpliterator());

int[] count = new int[1];
Expand All @@ -2117,7 +2118,7 @@ public void entrySpliterator_trySplit(Map<Integer, Integer> map, CacheContext co
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void entrySpliterator_estimateSize(Map<Integer, Integer> map, CacheContext context) {
Spliterator<Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
Spliterator<Map.Entry<Integer, Integer>> spliterator = map.entrySet().spliterator();
assertThat((int) spliterator.estimateSize(), is(map.size()));
}

Expand All @@ -2128,7 +2129,7 @@ public void entrySpliterator_estimateSize(Map<Integer, Integer> map, CacheContex
@CacheSpec(implementation = Implementation.Caffeine,
population = { Population.SINGLETON, Population.PARTIAL, Population.FULL })
public void writeThroughEntry(Map<Integer, Integer> map, CacheContext context) {
Entry<Integer, Integer> entry = map.entrySet().iterator().next();
Map.Entry<Integer, Integer> entry = map.entrySet().iterator().next();

entry.setValue(3);
assertThat(map.get(entry.getKey()), is(3));
Expand All @@ -2150,7 +2151,7 @@ public void writeThroughEntry_null(Map<Integer, Integer> map, CacheContext conte
@CacheSpec(implementation = Implementation.Caffeine,
population = { Population.SINGLETON, Population.PARTIAL, Population.FULL })
public void writeThroughEntry_serialize(Map<Integer, Integer> map, CacheContext context) {
Entry<Integer, Integer> entry = map.entrySet().iterator().next();
Map.Entry<Integer, Integer> entry = map.entrySet().iterator().next();
Object copy = SerializableTester.reserialize(entry);
assertThat(entry, is(equalTo(copy)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Spliterator;
Expand Down Expand Up @@ -117,6 +116,7 @@ public void clear(AsyncCache<Integer, Integer> cache, CacheContext context) {
/* ---------------- contains -------------- */

@CheckNoStats
@SuppressWarnings("ReturnValueIgnored")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void containsKey_null(AsyncCache<Integer, Integer> cache, CacheContext context) {
Expand All @@ -141,6 +141,7 @@ public void containsKey_absent(AsyncCache<Integer, Integer> cache, CacheContext
}

@CheckNoStats
@SuppressWarnings("ReturnValueIgnored")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void containsValue_null(AsyncCache<Integer, Integer> cache, CacheContext context) {
Expand Down Expand Up @@ -1663,7 +1664,7 @@ public void valueSpliterator_estimateSize(
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void entrySetToArray_null(AsyncCache<Integer, Integer> cache, CacheContext context) {
cache.asMap().entrySet().toArray((Entry<?, ?>[]) null);
cache.asMap().entrySet().toArray((Map.Entry<?, ?>[]) null);
}

@CheckNoStats
Expand All @@ -1673,20 +1674,20 @@ public void entriesToArray(AsyncCache<Integer, Integer> cache, CacheContext cont
int length = context.original().size();

@SuppressWarnings("unchecked")
Entry<Integer, CompletableFuture<Integer>>[] entries =
(Entry<Integer, CompletableFuture<Integer>>[])
cache.asMap().entrySet().toArray(new Entry<?, ?>[length]);
Map.Entry<Integer, CompletableFuture<Integer>>[] entries =
(Map.Entry<Integer, CompletableFuture<Integer>>[])
cache.asMap().entrySet().toArray(new Map.Entry<?, ?>[length]);
assertThat(entries.length, is(length));
for (Entry<Integer, CompletableFuture<Integer>> entry : entries) {
for (Map.Entry<Integer, CompletableFuture<Integer>> entry : entries) {
assertThat(context.original(), hasEntry(entry.getKey(), entry.getValue().join()));
}

Object[] array = cache.asMap().entrySet().toArray();
assertThat(array.length, is(length));
for (Object item : array) {
@SuppressWarnings("unchecked")
Entry<Integer, CompletableFuture<Integer>> entry =
(Entry<Integer, CompletableFuture<Integer>>) item;
Map.Entry<Integer, CompletableFuture<Integer>> entry =
(Map.Entry<Integer, CompletableFuture<Integer>>) item;
assertThat(context.original(), hasEntry(entry.getKey(), entry.getValue().join()));
}
}
Expand Down Expand Up @@ -1731,7 +1732,7 @@ public void entrySet_removeIf_null(AsyncCache<Integer, Integer> cache, CacheCont
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySet_removeIf(AsyncCache<Integer, Integer> cache, CacheContext context) {
Predicate<Entry<Integer, CompletableFuture<Integer>>> isEven =
Predicate<Map.Entry<Integer, CompletableFuture<Integer>>> isEven =
entry -> (entry.getValue().join() % 2) == 0;
boolean hasEven = cache.asMap().entrySet().stream().anyMatch(isEven);

Expand All @@ -1747,7 +1748,7 @@ public void entrySet_removeIf(AsyncCache<Integer, Integer> cache, CacheContext c
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySet(AsyncCache<Integer, Integer> cache, CacheContext context) {
Set<Entry<Integer, CompletableFuture<Integer>>> entries = cache.asMap().entrySet();
Set<Map.Entry<Integer, CompletableFuture<Integer>>> entries = cache.asMap().entrySet();
assertThat(entries.contains(new Object()), is(false));
assertThat(entries.remove(new Object()), is(false));
assertThat(entries, hasSize(context.original().size()));
Expand All @@ -1766,10 +1767,11 @@ public void entrySet(AsyncCache<Integer, Integer> cache, CacheContext context) {
@CheckNoStats
@Test(dataProvider = "caches")
public void entryIterator(AsyncCache<Integer, Integer> cache, CacheContext context) {
Iterator<Entry<Integer, CompletableFuture<Integer>>> i = cache.asMap().entrySet().iterator();
Iterator<Map.Entry<Integer, CompletableFuture<Integer>>> i =
cache.asMap().entrySet().iterator();
int iterations = 0;
while (i.hasNext()) {
Entry<Integer, CompletableFuture<Integer>> entry = i.next();
Map.Entry<Integer, CompletableFuture<Integer>> entry = i.next();
assertThat(cache.asMap(), hasEntry(entry.getKey(), entry.getValue()));
iterations++;
i.remove();
Expand Down Expand Up @@ -1833,7 +1835,7 @@ public void entrySpliterator_tryAdvance_null(
@Test(dataProvider = "caches")
public void entrySpliterator_tryAdvance(
AsyncCache<Integer, Integer> cache, CacheContext context) {
Spliterator<Entry<Integer, CompletableFuture<Integer>>> spliterator =
Spliterator<Map.Entry<Integer, CompletableFuture<Integer>>> spliterator =
cache.asMap().entrySet().spliterator();
int[] count = new int[1];
boolean advanced;
Expand All @@ -1852,9 +1854,9 @@ public void entrySpliterator_tryAdvance(
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySpliterator_trySplit(AsyncCache<Integer, Integer> cache, CacheContext context) {
Spliterator<Entry<Integer, CompletableFuture<Integer>>> spliterator =
Spliterator<Map.Entry<Integer, CompletableFuture<Integer>>> spliterator =
cache.asMap().entrySet().spliterator();
Spliterator<Entry<Integer, CompletableFuture<Integer>>> other = MoreObjects.firstNonNull(
Spliterator<Map.Entry<Integer, CompletableFuture<Integer>>> other = MoreObjects.firstNonNull(
spliterator.trySplit(), Spliterators.emptySpliterator());

int[] count = new int[1];
Expand All @@ -1868,7 +1870,7 @@ public void entrySpliterator_trySplit(AsyncCache<Integer, Integer> cache, CacheC
@Test(dataProvider = "caches")
public void entrySpliterator_estimateSize(
AsyncCache<Integer, Integer> cache, CacheContext context) {
Spliterator<Entry<Integer, CompletableFuture<Integer>>> spliterator =
Spliterator<Map.Entry<Integer, CompletableFuture<Integer>>> spliterator =
cache.asMap().entrySet().spliterator();
assertThat((int) spliterator.estimateSize(), is(cache.asMap().size()));
}
Expand All @@ -1879,7 +1881,8 @@ public void entrySpliterator_estimateSize(
@Test(dataProvider = "caches")
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL })
public void writeThroughEntry(AsyncCache<Integer, Integer> cache, CacheContext context) {
Entry<Integer, CompletableFuture<Integer>> entry = cache.asMap().entrySet().iterator().next();
Map.Entry<Integer, CompletableFuture<Integer>> entry =
cache.asMap().entrySet().iterator().next();
CompletableFuture<Integer> value = CompletableFuture.completedFuture(3);

entry.setValue(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -193,8 +192,8 @@ public void putWeighted_noOverflow() {
population = Population.EMPTY, maximumSize = Maximum.ONE)
public void evict_alreadyRemoved(Cache<Integer, Integer> cache, CacheContext context) {
BoundedLocalCache<Integer, Integer> localCache = asBoundedLocalCache(cache);
Entry<Integer, Integer> oldEntry = Iterables.get(context.absent().entrySet(), 0);
Entry<Integer, Integer> newEntry = Iterables.get(context.absent().entrySet(), 1);
Map.Entry<Integer, Integer> oldEntry = Iterables.get(context.absent().entrySet(), 0);
Map.Entry<Integer, Integer> newEntry = Iterables.get(context.absent().entrySet(), 1);

localCache.put(oldEntry.getKey(), oldEntry.getValue());
localCache.evictionLock.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void describeTo(Description description) {
}

@Override
@SuppressWarnings("NonCanonicalType")
protected boolean matchesSafely(Map<K, V> map, Description description) {
this.description = description;

Expand Down
Loading

0 comments on commit 56b3124

Please sign in to comment.