The following issues were found
guava/src/com/google/common/util/concurrent/ForwardingExecutorService.java
14 issues
Line: 42
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class ForwardingExecutorService extends ForwardingObject
implements ExecutorService {
/** Constructor for use by subclasses. */
protected ForwardingExecutorService() {}
@Override
protected abstract ExecutorService delegate();
Reported by PMD.
Line: 51
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return delegate().awaitTermination(timeout, unit);
}
@Override
public <T extends @Nullable Object> List<Future<T>> invokeAll(
Collection<? extends Callable<T>> tasks) throws InterruptedException {
Reported by PMD.
Line: 57
@Override
public <T extends @Nullable Object> List<Future<T>> invokeAll(
Collection<? extends Callable<T>> tasks) throws InterruptedException {
return delegate().invokeAll(tasks);
}
@Override
public <T extends @Nullable Object> List<Future<T>> invokeAll(
Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
Reported by PMD.
Line: 64
public <T extends @Nullable Object> List<Future<T>> invokeAll(
Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException {
return delegate().invokeAll(tasks, timeout, unit);
}
@Override
public <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException, ExecutionException {
Reported by PMD.
Line: 70
@Override
public <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException, ExecutionException {
return delegate().invokeAny(tasks);
}
@Override
public <T extends @Nullable Object> T invokeAny(
Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
Reported by PMD.
Line: 77
public <T extends @Nullable Object> T invokeAny(
Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return delegate().invokeAny(tasks, timeout, unit);
}
@Override
public boolean isShutdown() {
return delegate().isShutdown();
Reported by PMD.
Line: 82
@Override
public boolean isShutdown() {
return delegate().isShutdown();
}
@Override
public boolean isTerminated() {
return delegate().isTerminated();
Reported by PMD.
Line: 87
@Override
public boolean isTerminated() {
return delegate().isTerminated();
}
@Override
public void shutdown() {
delegate().shutdown();
Reported by PMD.
Line: 92
@Override
public void shutdown() {
delegate().shutdown();
}
@Override
public List<Runnable> shutdownNow() {
return delegate().shutdownNow();
Reported by PMD.
Line: 97
@Override
public List<Runnable> shutdownNow() {
return delegate().shutdownNow();
}
@Override
public void execute(Runnable command) {
delegate().execute(command);
Reported by PMD.
guava/src/com/google/common/primitives/UnsignedLongs.java
14 issues
Line: 457
* @throws IllegalArgumentException if {@code radix} is not between {@link Character#MIN_RADIX}
* and {@link Character#MAX_RADIX}.
*/
public static String toString(long x, int radix) {
checkArgument(
radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX,
"radix (%s) must be between Character.MIN_RADIX and Character.MAX_RADIX",
radix);
if (x == 0) {
Reported by PMD.
Line: 457
* @throws IllegalArgumentException if {@code radix} is not between {@link Character#MIN_RADIX}
* and {@link Character#MAX_RADIX}.
*/
public static String toString(long x, int radix) {
checkArgument(
radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX,
"radix (%s) must be between Character.MIN_RADIX and Character.MAX_RADIX",
radix);
if (x == 0) {
Reported by PMD.
Line: 457
* @throws IllegalArgumentException if {@code radix} is not between {@link Character#MIN_RADIX}
* and {@link Character#MAX_RADIX}.
*/
public static String toString(long x, int radix) {
checkArgument(
radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX,
"radix (%s) must be between Character.MIN_RADIX and Character.MAX_RADIX",
radix);
if (x == 0) {
Reported by PMD.
Line: 54
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class UnsignedLongs {
private UnsignedLongs() {}
public static final long MAX_VALUE = -1L; // Equivalent to 2^64 - 1
/**
Reported by PMD.
Line: 54
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class UnsignedLongs {
private UnsignedLongs() {}
public static final long MAX_VALUE = -1L; // Equivalent to 2^64 - 1
/**
Reported by PMD.
Line: 338
* Long#parseLong(String)})
*/
@CanIgnoreReturnValue
public static long parseUnsignedLong(String string, int radix) {
checkNotNull(string);
if (string.length() == 0) {
throw new NumberFormatException("empty string");
}
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
Reported by PMD.
Line: 186
*
* @since 23.1
*/
public static void sort(long[] array) {
checkNotNull(array);
sort(array, 0, array.length);
}
/**
Reported by PMD.
Line: 215
*
* @since 23.1
*/
public static void sortDescending(long[] array) {
checkNotNull(array);
sortDescending(array, 0, array.length);
}
/**
Reported by PMD.
Line: 347
throw new NumberFormatException("illegal radix: " + radix);
}
int maxSafePos = ParseOverflowDetection.maxSafeDigits[radix] - 1;
long value = 0;
for (int pos = 0; pos < string.length(); pos++) {
int digit = Character.digit(string.charAt(pos), radix);
if (digit == -1) {
throw new NumberFormatException(string);
Reported by PMD.
Line: 348
}
int maxSafePos = ParseOverflowDetection.maxSafeDigits[radix] - 1;
long value = 0;
for (int pos = 0; pos < string.length(); pos++) {
int digit = Character.digit(string.charAt(pos), radix);
if (digit == -1) {
throw new NumberFormatException(string);
}
Reported by PMD.
guava/src/com/google/common/escape/Escapers.java
14 issues
Line: 58
@Override
@CheckForNull
protected char[] escape(char c) {
// TODO: Fix tests not to call this directly and make it throw an error.
return null;
}
};
Reported by PMD.
Line: 37
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Escapers {
private Escapers() {}
/**
* Returns an {@link Escaper} that does no escaping, passing all character data through unchanged.
*/
Reported by PMD.
Line: 37
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Escapers {
private Escapers() {}
/**
* Returns an {@link Escaper} that does no escaping, passing all character data through unchanged.
*/
Reported by PMD.
Line: 98
*/
@Beta
public static final class Builder {
private final Map<Character, String> replacementMap = new HashMap<>();
private char safeMin = Character.MIN_VALUE;
private char safeMax = Character.MAX_VALUE;
@CheckForNull private String unsafeReplacement = null;
// The constructor is exposed via the builder() method above.
Reported by PMD.
Line: 99
@Beta
public static final class Builder {
private final Map<Character, String> replacementMap = new HashMap<>();
private char safeMin = Character.MIN_VALUE;
private char safeMax = Character.MAX_VALUE;
@CheckForNull private String unsafeReplacement = null;
// The constructor is exposed via the builder() method above.
private Builder() {}
Reported by PMD.
Line: 100
public static final class Builder {
private final Map<Character, String> replacementMap = new HashMap<>();
private char safeMin = Character.MIN_VALUE;
private char safeMax = Character.MAX_VALUE;
@CheckForNull private String unsafeReplacement = null;
// The constructor is exposed via the builder() method above.
private Builder() {}
Reported by PMD.
Line: 101
private final Map<Character, String> replacementMap = new HashMap<>();
private char safeMin = Character.MIN_VALUE;
private char safeMax = Character.MAX_VALUE;
@CheckForNull private String unsafeReplacement = null;
// The constructor is exposed via the builder() method above.
private Builder() {}
/**
Reported by PMD.
Line: 101
private final Map<Character, String> replacementMap = new HashMap<>();
private char safeMin = Character.MIN_VALUE;
private char safeMax = Character.MAX_VALUE;
@CheckForNull private String unsafeReplacement = null;
// The constructor is exposed via the builder() method above.
private Builder() {}
/**
Reported by PMD.
Line: 194
// In practice this shouldn't happen because it would be very odd not to
// extend either CharEscaper or UnicodeEscaper for non trivial cases.
throw new IllegalArgumentException(
"Cannot create a UnicodeEscaper from: " + escaper.getClass().getName());
}
/**
* Returns a string that would replace the given character in the specified escaper, or {@code
* null} if no replacement should be made. This method is intended for use in tests through the
Reported by PMD.
Line: 231
}
/** Private helper to wrap a CharEscaper as a UnicodeEscaper. */
private static UnicodeEscaper wrap(final CharEscaper escaper) {
return new UnicodeEscaper() {
@Override
@CheckForNull
protected char[] escape(int cp) {
// If a code point maps to a single character, just escape that.
Reported by PMD.
guava/src/com/google/common/reflect/AbstractInvocationHandler.java
14 issues
Line: 65
*/
@Override
@CheckForNull
public final Object invoke(Object proxy, Method method, @CheckForNull @Nullable Object[] args)
throws Throwable {
if (args == null) {
args = NO_ARGS;
}
if (args.length == 0 && method.getName().equals("hashCode")) {
Reported by PMD.
Line: 65
*/
@Override
@CheckForNull
public final Object invoke(Object proxy, Method method, @CheckForNull @Nullable Object[] args)
throws Throwable {
if (args == null) {
args = NO_ARGS;
}
if (args.length == 0 && method.getName().equals("hashCode")) {
Reported by PMD.
Line: 70
if (args == null) {
args = NO_ARGS;
}
if (args.length == 0 && method.getName().equals("hashCode")) {
return hashCode();
}
if (args.length == 1
&& method.getName().equals("equals")
&& method.getParameterTypes()[0] == Object.class) {
Reported by PMD.
Line: 70
if (args == null) {
args = NO_ARGS;
}
if (args.length == 0 && method.getName().equals("hashCode")) {
return hashCode();
}
if (args.length == 1
&& method.getName().equals("equals")
&& method.getParameterTypes()[0] == Object.class) {
Reported by PMD.
Line: 74
return hashCode();
}
if (args.length == 1
&& method.getName().equals("equals")
&& method.getParameterTypes()[0] == Object.class) {
Object arg = args[0];
if (arg == null) {
return false;
}
Reported by PMD.
Line: 74
return hashCode();
}
if (args.length == 1
&& method.getName().equals("equals")
&& method.getParameterTypes()[0] == Object.class) {
Object arg = args[0];
if (arg == null) {
return false;
}
Reported by PMD.
Line: 80
if (arg == null) {
return false;
}
if (proxy == arg) {
return true;
}
return isProxyOfSameInterfaces(arg, proxy.getClass())
&& equals(Proxy.getInvocationHandler(arg));
}
Reported by PMD.
Line: 86
return isProxyOfSameInterfaces(arg, proxy.getClass())
&& equals(Proxy.getInvocationHandler(arg));
}
if (args.length == 0 && method.getName().equals("toString")) {
return toString();
}
return handleInvocation(proxy, method, args);
}
Reported by PMD.
Line: 86
return isProxyOfSameInterfaces(arg, proxy.getClass())
&& equals(Proxy.getInvocationHandler(arg));
}
if (args.length == 0 && method.getName().equals("toString")) {
return toString();
}
return handleInvocation(proxy, method, args);
}
Reported by PMD.
Line: 116
* <p>Subclasses can override this method to provide custom equality.
*/
@Override
public boolean equals(@CheckForNull Object obj) {
return super.equals(obj);
}
/**
* By default delegates to {@link Object#hashCode}. The dynamic proxies' {@code hashCode()} will
Reported by PMD.
guava/src/com/google/common/hash/AbstractHashFunction.java
14 issues
Line: 36
@Override
public <T extends @Nullable Object> HashCode hashObject(
@ParametricNullness T instance, Funnel<? super T> funnel) {
return newHasher().putObject(instance, funnel).hash();
}
@Override
public HashCode hashUnencodedChars(CharSequence input) {
int len = input.length();
Reported by PMD.
Line: 36
@Override
public <T extends @Nullable Object> HashCode hashObject(
@ParametricNullness T instance, Funnel<? super T> funnel) {
return newHasher().putObject(instance, funnel).hash();
}
@Override
public HashCode hashUnencodedChars(CharSequence input) {
int len = input.length();
Reported by PMD.
Line: 42
@Override
public HashCode hashUnencodedChars(CharSequence input) {
int len = input.length();
return newHasher(len * 2).putUnencodedChars(input).hash();
}
@Override
public HashCode hashString(CharSequence input, Charset charset) {
return newHasher().putString(input, charset).hash();
Reported by PMD.
Line: 42
@Override
public HashCode hashUnencodedChars(CharSequence input) {
int len = input.length();
return newHasher(len * 2).putUnencodedChars(input).hash();
}
@Override
public HashCode hashString(CharSequence input, Charset charset) {
return newHasher().putString(input, charset).hash();
Reported by PMD.
Line: 47
@Override
public HashCode hashString(CharSequence input, Charset charset) {
return newHasher().putString(input, charset).hash();
}
@Override
public HashCode hashInt(int input) {
return newHasher(4).putInt(input).hash();
Reported by PMD.
Line: 47
@Override
public HashCode hashString(CharSequence input, Charset charset) {
return newHasher().putString(input, charset).hash();
}
@Override
public HashCode hashInt(int input) {
return newHasher(4).putInt(input).hash();
Reported by PMD.
Line: 52
@Override
public HashCode hashInt(int input) {
return newHasher(4).putInt(input).hash();
}
@Override
public HashCode hashLong(long input) {
return newHasher(8).putLong(input).hash();
Reported by PMD.
Line: 52
@Override
public HashCode hashInt(int input) {
return newHasher(4).putInt(input).hash();
}
@Override
public HashCode hashLong(long input) {
return newHasher(8).putLong(input).hash();
Reported by PMD.
Line: 57
@Override
public HashCode hashLong(long input) {
return newHasher(8).putLong(input).hash();
}
@Override
public HashCode hashBytes(byte[] input) {
return hashBytes(input, 0, input.length);
Reported by PMD.
Line: 57
@Override
public HashCode hashLong(long input) {
return newHasher(8).putLong(input).hash();
}
@Override
public HashCode hashBytes(byte[] input) {
return hashBytes(input, 0, input.length);
Reported by PMD.
guava/src/com/google/common/collect/ImmutableMapEntrySet.java
14 issues
Line: 36
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
static final class RegularEntrySet<K, V> extends ImmutableMapEntrySet<K, V> {
private final transient ImmutableMap<K, V> map;
private final transient ImmutableList<Entry<K, V>> entries;
RegularEntrySet(ImmutableMap<K, V> map, Entry<K, V>[] entries) {
Reported by PMD.
Line: 37
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
static final class RegularEntrySet<K, V> extends ImmutableMapEntrySet<K, V> {
private final transient ImmutableMap<K, V> map;
private final transient ImmutableList<Entry<K, V>> entries;
RegularEntrySet(ImmutableMap<K, V> map, Entry<K, V>[] entries) {
this(map, ImmutableList.<Entry<K, V>>asImmutableList(entries));
Reported by PMD.
Line: 38
@ElementTypesAreNonnullByDefault
abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
static final class RegularEntrySet<K, V> extends ImmutableMapEntrySet<K, V> {
private final transient ImmutableMap<K, V> map;
private final transient ImmutableList<Entry<K, V>> entries;
RegularEntrySet(ImmutableMap<K, V> map, Entry<K, V>[] entries) {
this(map, ImmutableList.<Entry<K, V>>asImmutableList(entries));
}
Reported by PMD.
Line: 88
@Override
public int size() {
return map().size();
}
@Override
public boolean contains(@CheckForNull Object object) {
if (object instanceof Entry) {
Reported by PMD.
Line: 95
public boolean contains(@CheckForNull Object object) {
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
V value = map().get(entry.getKey());
return value != null && value.equals(entry.getValue());
}
return false;
}
Reported by PMD.
Line: 95
public boolean contains(@CheckForNull Object object) {
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
V value = map().get(entry.getKey());
return value != null && value.equals(entry.getValue());
}
return false;
}
Reported by PMD.
Line: 96
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
V value = map().get(entry.getKey());
return value != null && value.equals(entry.getValue());
}
return false;
}
@Override
Reported by PMD.
Line: 96
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
V value = map().get(entry.getKey());
return value != null && value.equals(entry.getValue());
}
return false;
}
@Override
Reported by PMD.
Line: 103
@Override
boolean isPartialView() {
return map().isPartialView();
}
@Override
@GwtIncompatible // not used in GWT
boolean isHashCodeFast() {
Reported by PMD.
Line: 109
@Override
@GwtIncompatible // not used in GWT
boolean isHashCodeFast() {
return map().isHashCodeFast();
}
@Override
public int hashCode() {
return map().hashCode();
Reported by PMD.
guava/src/com/google/common/util/concurrent/TrustedListenableFutureTask.java
14 issues
Line: 68
* <p>{@code volatile} is required for j2objc transpiling:
* https://developers.google.com/j2objc/guides/j2objc-memory-model#atomicity
*/
@CheckForNull private volatile InterruptibleTask<?> task;
TrustedListenableFutureTask(Callable<V> callable) {
this.task = new TrustedFutureInterruptibleTask(callable);
}
Reported by PMD.
Line: 88
* In the Async case, we may have called setFuture(pendingFuture), in which case afterDone()
* won't have been called yet.
*/
this.task = null;
}
@Override
protected void afterDone() {
super.afterDone();
Reported by PMD.
Line: 98
if (wasInterrupted()) {
InterruptibleTask<?> localTask = task;
if (localTask != null) {
localTask.interruptTask();
}
}
this.task = null;
}
Reported by PMD.
Line: 102
}
}
this.task = null;
}
@Override
@CheckForNull
protected String pendingToString() {
Reported by PMD.
Line: 116
}
@WeakOuter
private final class TrustedFutureInterruptibleTask extends InterruptibleTask<V> {
private final Callable<V> callable;
TrustedFutureInterruptibleTask(Callable<V> callable) {
this.callable = checkNotNull(callable);
}
Reported by PMD.
Line: 117
@WeakOuter
private final class TrustedFutureInterruptibleTask extends InterruptibleTask<V> {
private final Callable<V> callable;
TrustedFutureInterruptibleTask(Callable<V> callable) {
this.callable = checkNotNull(callable);
}
Reported by PMD.
Line: 125
@Override
final boolean isDone() {
return TrustedListenableFutureTask.this.isDone();
}
@Override
@ParametricNullness
V runInterruptibly() throws Exception {
Reported by PMD.
Line: 125
@Override
final boolean isDone() {
return TrustedListenableFutureTask.this.isDone();
}
@Override
@ParametricNullness
V runInterruptibly() throws Exception {
Reported by PMD.
Line: 136
@Override
void afterRanInterruptiblySuccess(@ParametricNullness V result) {
TrustedListenableFutureTask.this.set(result);
}
@Override
void afterRanInterruptiblyFailure(Throwable error) {
setException(error);
Reported by PMD.
Line: 136
@Override
void afterRanInterruptiblySuccess(@ParametricNullness V result) {
TrustedListenableFutureTask.this.set(result);
}
@Override
void afterRanInterruptiblyFailure(Throwable error) {
setException(error);
Reported by PMD.
guava/src/com/google/common/hash/FarmHashFingerprint64.java
14 issues
Line: 102
* new arrays every time.
*/
private static void weakHashLength32WithSeeds(
byte[] bytes, int offset, long seedA, long seedB, long[] output) {
long part1 = load64(bytes, offset);
long part2 = load64(bytes, offset + 8);
long part3 = load64(bytes, offset + 16);
long part4 = load64(bytes, offset + 24);
Reported by PMD.
Line: 102
* new arrays every time.
*/
private static void weakHashLength32WithSeeds(
byte[] bytes, int offset, long seedA, long seedB, long[] output) {
long part1 = load64(bytes, offset);
long part2 = load64(bytes, offset + 8);
long part3 = load64(bytes, offset + 16);
long part4 = load64(bytes, offset + 24);
Reported by PMD.
Line: 102
* new arrays every time.
*/
private static void weakHashLength32WithSeeds(
byte[] bytes, int offset, long seedA, long seedB, long[] output) {
long part1 = load64(bytes, offset);
long part2 = load64(bytes, offset + 8);
long part3 = load64(bytes, offset + 16);
long part4 = load64(bytes, offset + 24);
Reported by PMD.
Line: 102
* new arrays every time.
*/
private static void weakHashLength32WithSeeds(
byte[] bytes, int offset, long seedA, long seedB, long[] output) {
long part1 = load64(bytes, offset);
long part2 = load64(bytes, offset + 8);
long part3 = load64(bytes, offset + 16);
long part4 = load64(bytes, offset + 24);
Reported by PMD.
Line: 102
* new arrays every time.
*/
private static void weakHashLength32WithSeeds(
byte[] bytes, int offset, long seedA, long seedB, long[] output) {
long part1 = load64(bytes, offset);
long part2 = load64(bytes, offset + 8);
long part3 = load64(bytes, offset + 16);
long part4 = load64(bytes, offset + 24);
Reported by PMD.
Line: 172
/*
* Compute an 8-byte hash of a byte array of length greater than 64 bytes.
*/
private static long hashLength65Plus(byte[] bytes, int offset, int length) {
final int seed = 81;
// For strings over 64 bytes we loop. Internal state consists of 56 bytes: v, w, x, y, and z.
long x = seed;
@SuppressWarnings("ConstantOverflow")
long y = seed * K1 + 113;
Reported by PMD.
Line: 172
/*
* Compute an 8-byte hash of a byte array of length greater than 64 bytes.
*/
private static long hashLength65Plus(byte[] bytes, int offset, int length) {
final int seed = 81;
// For strings over 64 bytes we loop. Internal state consists of 56 bytes: v, w, x, y, and z.
long x = seed;
@SuppressWarnings("ConstantOverflow")
long y = seed * K1 + 113;
Reported by PMD.
Line: 42
* @author Geoff Pike
*/
@ElementTypesAreNonnullByDefault
final class FarmHashFingerprint64 extends AbstractNonStreamingHashFunction {
static final HashFunction FARMHASH_FINGERPRINT_64 = new FarmHashFingerprint64();
// Some primes between 2^63 and 2^64 for various uses.
private static final long K0 = 0xc3a5c85c97cb3127L;
private static final long K1 = 0xb492b66fbe98f273L;
Reported by PMD.
Line: 70
@VisibleForTesting
static long fingerprint(byte[] bytes, int offset, int length) {
if (length <= 32) {
if (length <= 16) {
return hashLength0to16(bytes, offset, length);
} else {
return hashLength17to32(bytes, offset, length);
}
Reported by PMD.
Line: 71
@VisibleForTesting
static long fingerprint(byte[] bytes, int offset, int length) {
if (length <= 32) {
if (length <= 16) {
return hashLength0to16(bytes, offset, length);
} else {
return hashLength17to32(bytes, offset, length);
}
} else if (length <= 64) {
Reported by PMD.
guava-tests/test/com/google/common/util/concurrent/ListenableFutureTester.java
14 issues
Line: 41
*/
public class ListenableFutureTester {
private final ExecutorService exec;
private final ListenableFuture<?> future;
private final CountDownLatch latch;
public ListenableFutureTester(ListenableFuture<?> future) {
this.exec = Executors.newCachedThreadPool();
Reported by PMD.
Line: 42
public class ListenableFutureTester {
private final ExecutorService exec;
private final ListenableFuture<?> future;
private final CountDownLatch latch;
public ListenableFutureTester(ListenableFuture<?> future) {
this.exec = Executors.newCachedThreadPool();
this.future = checkNotNull(future);
Reported by PMD.
Line: 43
private final ExecutorService exec;
private final ListenableFuture<?> future;
private final CountDownLatch latch;
public ListenableFutureTester(ListenableFuture<?> future) {
this.exec = Executors.newCachedThreadPool();
this.future = checkNotNull(future);
this.latch = new CountDownLatch(1);
Reported by PMD.
Line: 51
this.latch = new CountDownLatch(1);
}
public void setUp() {
future.addListener(
new Runnable() {
@Override
public void run() {
latch.countDown();
Reported by PMD.
Line: 66
assertFalse(future.isCancelled());
}
public void tearDown() {
exec.shutdown();
}
public void testCompletedFuture(@Nullable Object expectedValue)
throws InterruptedException, ExecutionException {
Reported by PMD.
Line: 70
exec.shutdown();
}
public void testCompletedFuture(@Nullable Object expectedValue)
throws InterruptedException, ExecutionException {
assertTrue(future.isDone());
assertFalse(future.isCancelled());
assertTrue(latch.await(5, TimeUnit.SECONDS));
Reported by PMD.
Line: 70
exec.shutdown();
}
public void testCompletedFuture(@Nullable Object expectedValue)
throws InterruptedException, ExecutionException {
assertTrue(future.isDone());
assertFalse(future.isCancelled());
assertTrue(latch.await(5, TimeUnit.SECONDS));
Reported by PMD.
Line: 82
assertEquals(expectedValue, future.get());
}
public void testCancelledFuture() throws InterruptedException, ExecutionException {
assertTrue(future.isDone());
assertTrue(future.isCancelled());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(future.isDone());
Reported by PMD.
Line: 82
assertEquals(expectedValue, future.get());
}
public void testCancelledFuture() throws InterruptedException, ExecutionException {
assertTrue(future.isDone());
assertTrue(future.isCancelled());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(future.isDone());
Reported by PMD.
Line: 97
}
}
public void testFailedFuture(@Nullable String message) throws InterruptedException {
assertTrue(future.isDone());
assertFalse(future.isCancelled());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(future.isDone());
Reported by PMD.
guava/src/com/google/common/util/concurrent/AtomicLongMap.java
14 issues
Line: 59
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class AtomicLongMap<K> implements Serializable {
private final ConcurrentHashMap<K, Long> map;
private AtomicLongMap(ConcurrentHashMap<K, Long> map) {
this.map = checkNotNull(map);
}
Reported by PMD.
Line: 59
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class AtomicLongMap<K> implements Serializable {
private final ConcurrentHashMap<K, Long> map;
private AtomicLongMap(ConcurrentHashMap<K, Long> map) {
this.map = checkNotNull(map);
}
Reported by PMD.
Line: 60
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class AtomicLongMap<K> implements Serializable {
private final ConcurrentHashMap<K, Long> map;
private AtomicLongMap(ConcurrentHashMap<K, Long> map) {
this.map = checkNotNull(map);
}
Reported by PMD.
Line: 74
/** Creates an {@code AtomicLongMap} with the same mappings as the specified {@code Map}. */
public static <K> AtomicLongMap<K> create(Map<? extends K, ? extends Long> m) {
AtomicLongMap<K> result = create();
result.putAll(m);
return result;
}
/**
* Returns the value associated with {@code key}, or zero if there is no value associated with
Reported by PMD.
Line: 225
@CanIgnoreReturnValue
public long remove(K key) {
Long result = map.remove(key);
return (result == null) ? 0L : result.longValue();
}
/**
* If {@code (key, value)} is currently in the map, this method removes it and returns true;
* otherwise, this method returns false.
Reported by PMD.
Line: 254
* zero values have been removed and others have not.
*/
public void removeAllZeros() {
map.values().removeIf(x -> x == 0);
}
/**
* Returns the sum of all values in this map.
*
Reported by PMD.
Line: 263
* <p>This method is not atomic: the sum may or may not include other concurrent operations.
*/
public long sum() {
return map.values().stream().mapToLong(Long::longValue).sum();
}
@CheckForNull private transient Map<K, Long> asMap;
/** Returns a live, read-only view of the map backing this {@code AtomicLongMap}. */
Reported by PMD.
Line: 263
* <p>This method is not atomic: the sum may or may not include other concurrent operations.
*/
public long sum() {
return map.values().stream().mapToLong(Long::longValue).sum();
}
@CheckForNull private transient Map<K, Long> asMap;
/** Returns a live, read-only view of the map backing this {@code AtomicLongMap}. */
Reported by PMD.
Line: 263
* <p>This method is not atomic: the sum may or may not include other concurrent operations.
*/
public long sum() {
return map.values().stream().mapToLong(Long::longValue).sum();
}
@CheckForNull private transient Map<K, Long> asMap;
/** Returns a live, read-only view of the map backing this {@code AtomicLongMap}. */
Reported by PMD.
Line: 266
return map.values().stream().mapToLong(Long::longValue).sum();
}
@CheckForNull private transient Map<K, Long> asMap;
/** Returns a live, read-only view of the map backing this {@code AtomicLongMap}. */
public Map<K, Long> asMap() {
Map<K, Long> result = asMap;
return (result == null) ? asMap = createAsMap() : result;
Reported by PMD.