The following issues were found
guava-tests/test/com/google/common/util/concurrent/MonitorTestCase.java
41 issues
Line: 30
* @author Justin T. Sampson
*/
public abstract class MonitorTestCase extends TestCase {
public class TestGuard extends Monitor.Guard {
private volatile boolean satisfied;
public TestGuard(boolean satisfied) {
Reported by PMD.
Line: 50
}
}
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
Reported by PMD.
Line: 51
}
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
Reported by PMD.
Line: 52
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
Reported by PMD.
Line: 53
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
}
Reported by PMD.
Line: 54
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
}
Reported by PMD.
Line: 60
this.interruptible = interruptible;
}
@Override
protected final void setUp() throws Exception {
boolean fair = new Random().nextBoolean();
monitor = new Monitor(fair);
tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
Reported by PMD.
Line: 68
tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
}
@Override
protected final void tearDown() {
tearDownStack.runTearDown();
}
private String enter() {
Reported by PMD.
Line: 101
return "leave";
}
public final void testMutualExclusion() throws Exception {
thread1.callAndAssertReturns(enter());
thread2.callAndAssertBlocks(enter());
thread1.callAndAssertReturns(leave());
thread2.assertPriorCallReturns(enter());
}
Reported by PMD.
Line: 101
return "leave";
}
public final void testMutualExclusion() throws Exception {
thread1.callAndAssertReturns(enter());
thread2.callAndAssertBlocks(enter());
thread1.callAndAssertReturns(leave());
thread2.assertPriorCallReturns(enter());
}
Reported by PMD.
guava/src/com/google/common/collect/CollectSpliterators.java
41 issues
Line: 58
checkArgument((extraCharacteristics & Spliterator.SORTED) != 0);
}
class WithCharacteristics implements Spliterator<T> {
private final Spliterator.OfInt delegate;
WithCharacteristics(Spliterator.OfInt delegate) {
this.delegate = delegate;
}
Reported by PMD.
Line: 104
}
}
}
return new WithCharacteristics(IntStream.range(0, size).spliterator());
}
/**
* Returns a {@code Spliterator} over the elements of {@code fromSpliterator} mapped by {@code
* function}.
Reported by PMD.
Line: 156
checkNotNull(fromSpliterator);
checkNotNull(predicate);
class Splitr implements Spliterator<T>, Consumer<T> {
@CheckForNull T holder = null;
@Override
public void accept(@ParametricNullness T t) {
this.holder = t;
}
Reported by PMD.
Line: 156
checkNotNull(fromSpliterator);
checkNotNull(predicate);
class Splitr implements Spliterator<T>, Consumer<T> {
@CheckForNull T holder = null;
@Override
public void accept(@ParametricNullness T t) {
this.holder = t;
}
Reported by PMD.
Line: 174
return true;
}
} finally {
holder = null;
}
}
return false;
}
Reported by PMD.
Line: 222
long topSize) {
checkArgument(
(topCharacteristics & Spliterator.SUBSIZED) == 0,
"flatMap does not support SUBSIZED characteristic");
checkArgument(
(topCharacteristics & Spliterator.SORTED) == 0,
"flatMap does not support SORTED characteristic");
checkNotNull(fromSpliterator);
checkNotNull(function);
Reported by PMD.
Line: 225
"flatMap does not support SUBSIZED characteristic");
checkArgument(
(topCharacteristics & Spliterator.SORTED) == 0,
"flatMap does not support SORTED characteristic");
checkNotNull(fromSpliterator);
checkNotNull(function);
return new FlatMapSpliteratorOfObject<InElementT, OutElementT>(
null, fromSpliterator, function, topCharacteristics, topSize);
}
Reported by PMD.
Line: 321
long estSplitSize);
}
@Weak @CheckForNull OutSpliteratorT prefix;
final Spliterator<InElementT> from;
final Function<? super InElementT, OutSpliteratorT> function;
final Factory<InElementT, OutSpliteratorT> factory;
int characteristics;
long estimatedSize;
Reported by PMD.
Line: 322
}
@Weak @CheckForNull OutSpliteratorT prefix;
final Spliterator<InElementT> from;
final Function<? super InElementT, OutSpliteratorT> function;
final Factory<InElementT, OutSpliteratorT> factory;
int characteristics;
long estimatedSize;
Reported by PMD.
Line: 323
@Weak @CheckForNull OutSpliteratorT prefix;
final Spliterator<InElementT> from;
final Function<? super InElementT, OutSpliteratorT> function;
final Factory<InElementT, OutSpliteratorT> factory;
int characteristics;
long estimatedSize;
FlatMapSpliterator(
Reported by PMD.
guava/src/com/google/common/collect/ImmutableRangeMap.java
41 issues
Line: 50
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 50
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 50
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 90
return (ImmutableRangeMap<K, V>) rangeMap;
}
Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
rangesBuilder.add(entry.getKey());
valuesBuilder.add(entry.getValue());
}
Reported by PMD.
Line: 91
}
Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
rangesBuilder.add(entry.getKey());
valuesBuilder.add(entry.getValue());
}
return new ImmutableRangeMap<>(rangesBuilder.build(), valuesBuilder.build());
Reported by PMD.
Line: 111
*/
@DoNotMock
public static final class Builder<K extends Comparable<?>, V> {
private final List<Entry<Range<K>, V>> entries;
public Builder() {
this.entries = Lists.newArrayList();
}
Reported by PMD.
Line: 134
/** Copies all associations from the specified range map into this builder. */
@CanIgnoreReturnValue
public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) {
for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
put(entry.getKey(), entry.getValue());
}
return this;
}
Reported by PMD.
Line: 153
* @throws IllegalArgumentException if any two ranges inserted into this builder overlap
*/
public ImmutableRangeMap<K, V> build() {
Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Reported by PMD.
Line: 153
* @throws IllegalArgumentException if any two ranges inserted into this builder overlap
*/
public ImmutableRangeMap<K, V> build() {
Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Reported by PMD.
Line: 157
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Range<K> prevRange = entries.get(i - 1).getKey();
if (range.isConnected(prevRange) && !range.intersection(prevRange).isEmpty()) {
throw new IllegalArgumentException(
"Overlapping ranges: range " + prevRange + " overlaps with entry " + range);
Reported by PMD.
guava/src/com/google/common/util/concurrent/ExecutionSequencer.java
41 issues
Line: 95
}
/** This reference acts as a pointer tracking the head of a linked list of ListenableFutures. */
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
Reported by PMD.
Line: 98
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
* This object is unsafely published, but avoids problematic races by relying exclusively on the
* identity equality of its Thread field so that the task field is only accessed by a single
* thread.
Reported by PMD.
Line: 98
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
* This object is unsafely published, but avoids problematic races by relying exclusively on the
* identity equality of its Thread field so that the task field is only accessed by a single
* thread.
Reported by PMD.
Line: 129
* All the states where thread != currentThread are identical for our purposes, and so even
* though it's racy, we don't care which of those values we get, so no need to synchronize.
*/
@CheckForNull Thread thread;
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
Reported by PMD.
Line: 131
*/
@CheckForNull Thread thread;
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
/**
Reported by PMD.
Line: 133
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
/**
* Enqueues a task to run when the previous task (if any) completes.
*
Reported by PMD.
Line: 206
// Invoke our task once the previous future completes.
final TrustedListenableFutureTask<T> taskFuture = TrustedListenableFutureTask.create(task);
oldFuture.addListener(taskFuture, taskExecutor);
final ListenableFuture<T> outputFuture = Futures.nonCancellationPropagating(taskFuture);
// newFuture's lifetime is determined by taskFuture, which can't complete before oldFuture
// unless taskFuture is cancelled, in which case it falls back to oldFuture. This ensures that
Reported by PMD.
Line: 257
// Adding the listener to both futures guarantees that newFuture will aways be set. Adding to
// taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
// propagates cancellation if the callable has not yet been invoked.
outputFuture.addListener(listener, directExecutor());
taskFuture.addListener(listener, directExecutor());
return outputFuture;
}
Reported by PMD.
Line: 258
// taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
// propagates cancellation if the callable has not yet been invoked.
outputFuture.addListener(listener, directExecutor());
taskFuture.addListener(listener, directExecutor());
return outputFuture;
}
enum RunningState {
Reported by PMD.
Line: 287
* properties; for example, calling WeakReference.get() on Android will block during an
* otherwise-concurrent GC cycle.
*/
private static final class TaskNonReentrantExecutor extends AtomicReference<RunningState>
implements Executor, Runnable {
/**
* Used to update and read the latestTaskQueue field. Set to null once the runnable has been run
* or queued.
Reported by PMD.
android/guava/src/com/google/common/cache/CacheBuilder.java
41 issues
Line: 195
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
Reported by PMD.
Line: 195
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
Reported by PMD.
Line: 195
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
Reported by PMD.
Line: 195
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
Reported by PMD.
Line: 195
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
Reported by PMD.
Line: 199
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_EXPIRATION_NANOS = 0;
@SuppressWarnings("GoodTime") // should be a java.time.Duration
private static final int DEFAULT_REFRESH_NANOS = 0;
Reported by PMD.
Line: 268
static final int UNSET_INT = -1;
boolean strictParsing = true;
int initialCapacity = UNSET_INT;
int concurrencyLevel = UNSET_INT;
long maximumSize = UNSET_INT;
long maximumWeight = UNSET_INT;
Reported by PMD.
Line: 270
boolean strictParsing = true;
int initialCapacity = UNSET_INT;
int concurrencyLevel = UNSET_INT;
long maximumSize = UNSET_INT;
long maximumWeight = UNSET_INT;
@Nullable Weigher<? super K, ? super V> weigher;
Reported by PMD.
Line: 270
boolean strictParsing = true;
int initialCapacity = UNSET_INT;
int concurrencyLevel = UNSET_INT;
long maximumSize = UNSET_INT;
long maximumWeight = UNSET_INT;
@Nullable Weigher<? super K, ? super V> weigher;
Reported by PMD.
Line: 271
boolean strictParsing = true;
int initialCapacity = UNSET_INT;
int concurrencyLevel = UNSET_INT;
long maximumSize = UNSET_INT;
long maximumWeight = UNSET_INT;
@Nullable Weigher<? super K, ? super V> weigher;
@Nullable Strength keyStrength;
Reported by PMD.
android/guava/src/com/google/common/collect/ImmutableRangeMap.java
41 issues
Line: 46
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 46
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 46
@Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());
/**
Reported by PMD.
Line: 73
return (ImmutableRangeMap<K, V>) rangeMap;
}
Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
rangesBuilder.add(entry.getKey());
valuesBuilder.add(entry.getValue());
}
Reported by PMD.
Line: 74
}
Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
rangesBuilder.add(entry.getKey());
valuesBuilder.add(entry.getValue());
}
return new ImmutableRangeMap<>(rangesBuilder.build(), valuesBuilder.build());
Reported by PMD.
Line: 94
*/
@DoNotMock
public static final class Builder<K extends Comparable<?>, V> {
private final List<Entry<Range<K>, V>> entries;
public Builder() {
this.entries = Lists.newArrayList();
}
Reported by PMD.
Line: 117
/** Copies all associations from the specified range map into this builder. */
@CanIgnoreReturnValue
public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) {
for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
put(entry.getKey(), entry.getValue());
}
return this;
}
Reported by PMD.
Line: 136
* @throws IllegalArgumentException if any two ranges inserted into this builder overlap
*/
public ImmutableRangeMap<K, V> build() {
Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Reported by PMD.
Line: 136
* @throws IllegalArgumentException if any two ranges inserted into this builder overlap
*/
public ImmutableRangeMap<K, V> build() {
Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Reported by PMD.
Line: 140
ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
for (int i = 0; i < entries.size(); i++) {
Range<K> range = entries.get(i).getKey();
if (i > 0) {
Range<K> prevRange = entries.get(i - 1).getKey();
if (range.isConnected(prevRange) && !range.intersection(prevRange).isEmpty()) {
throw new IllegalArgumentException(
"Overlapping ranges: range " + prevRange + " overlaps with entry " + range);
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/MonitorTestCase.java
41 issues
Line: 30
* @author Justin T. Sampson
*/
public abstract class MonitorTestCase extends TestCase {
public class TestGuard extends Monitor.Guard {
private volatile boolean satisfied;
public TestGuard(boolean satisfied) {
Reported by PMD.
Line: 50
}
}
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
Reported by PMD.
Line: 51
}
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
Reported by PMD.
Line: 52
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
Reported by PMD.
Line: 53
private final boolean interruptible;
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
}
Reported by PMD.
Line: 54
private Monitor monitor;
private final TearDownStack tearDownStack = new TearDownStack(true);
private TestThread<Monitor> thread1;
private TestThread<Monitor> thread2;
protected MonitorTestCase(boolean interruptible) {
this.interruptible = interruptible;
}
Reported by PMD.
Line: 60
this.interruptible = interruptible;
}
@Override
protected final void setUp() throws Exception {
boolean fair = new Random().nextBoolean();
monitor = new Monitor(fair);
tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
Reported by PMD.
Line: 68
tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
}
@Override
protected final void tearDown() {
tearDownStack.runTearDown();
}
private String enter() {
Reported by PMD.
Line: 101
return "leave";
}
public final void testMutualExclusion() throws Exception {
thread1.callAndAssertReturns(enter());
thread2.callAndAssertBlocks(enter());
thread1.callAndAssertReturns(leave());
thread2.assertPriorCallReturns(enter());
}
Reported by PMD.
Line: 101
return "leave";
}
public final void testMutualExclusion() throws Exception {
thread1.callAndAssertReturns(enter());
thread2.callAndAssertBlocks(enter());
thread1.callAndAssertReturns(leave());
thread2.assertPriorCallReturns(enter());
}
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/AtomicLongMapBasherTest.java
41 issues
Line: 35
*/
@GwtIncompatible // threads
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
Reported by PMD.
Line: 36
@GwtIncompatible // threads
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 53
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
Reported by PMD.
Line: 55
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
int behavior = random.nextInt(10);
switch (behavior) {
Reported by PMD.
Line: 114
});
}
threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));
assertEquals(sum.get(), map.get(key));
}
}
Reported by PMD.
Line: 115
}
threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));
assertEquals(sum.get(), map.get(key));
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java
41 issues
Line: 44
}
@Override
protected abstract SortedMap<K, V> makeEmptyMap() throws UnsupportedOperationException;
@Override
protected abstract SortedMap<K, V> makePopulatedMap() throws UnsupportedOperationException;
@Override
Reported by PMD.
Line: 47
protected abstract SortedMap<K, V> makeEmptyMap() throws UnsupportedOperationException;
@Override
protected abstract SortedMap<K, V> makePopulatedMap() throws UnsupportedOperationException;
@Override
protected SortedMap<K, V> makeEitherMap() {
try {
return makePopulatedMap();
Reported by PMD.
Line: 58
}
}
public void testTailMapWriteThrough() {
final SortedMap<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
Reported by PMD.
Line: 58
}
}
public void testTailMapWriteThrough() {
final SortedMap<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
Reported by PMD.
Line: 65
} catch (UnsupportedOperationException e) {
return;
}
if (map.size() < 2 || !supportsPut) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
Reported by PMD.
Line: 68
if (map.size() < 2 || !supportsPut) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
Reported by PMD.
Line: 68
if (map.size() < 2 || !supportsPut) {
return;
}
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
Reported by PMD.
Line: 71
Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
subMap.put(key, value);
assertEquals(secondEntry.getValue(), value);
assertEquals(map.get(key), value);
Reported by PMD.
Line: 72
Entry<K, V> firstEntry = iterator.next();
Entry<K, V> secondEntry = iterator.next();
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
subMap.put(key, value);
assertEquals(secondEntry.getValue(), value);
assertEquals(map.get(key), value);
try {
Reported by PMD.
Line: 74
K key = secondEntry.getKey();
SortedMap<K, V> subMap = map.tailMap(key);
V value = getValueNotInPopulatedMap();
subMap.put(key, value);
assertEquals(secondEntry.getValue(), value);
assertEquals(map.get(key), value);
try {
subMap.put(firstEntry.getKey(), value);
fail("Expected IllegalArgumentException");
Reported by PMD.
android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java
41 issues
Line: 95
}
/** This reference acts as a pointer tracking the head of a linked list of ListenableFutures. */
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
Reported by PMD.
Line: 98
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
* This object is unsafely published, but avoids problematic races by relying exclusively on the
* identity equality of its Thread field so that the task field is only accessed by a single
* thread.
Reported by PMD.
Line: 98
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
new AtomicReference<>(immediateVoidFuture());
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
/**
* This object is unsafely published, but avoids problematic races by relying exclusively on the
* identity equality of its Thread field so that the task field is only accessed by a single
* thread.
Reported by PMD.
Line: 129
* All the states where thread != currentThread are identical for our purposes, and so even
* though it's racy, we don't care which of those values we get, so no need to synchronize.
*/
@CheckForNull Thread thread;
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
Reported by PMD.
Line: 131
*/
@CheckForNull Thread thread;
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
/**
Reported by PMD.
Line: 133
/** Only used by the thread associated with this object */
@CheckForNull Runnable nextTask;
/** Only used by the thread associated with this object */
@CheckForNull Executor nextExecutor;
}
/**
* Enqueues a task to run when the previous task (if any) completes.
*
Reported by PMD.
Line: 206
// Invoke our task once the previous future completes.
final TrustedListenableFutureTask<T> taskFuture = TrustedListenableFutureTask.create(task);
oldFuture.addListener(taskFuture, taskExecutor);
final ListenableFuture<T> outputFuture = Futures.nonCancellationPropagating(taskFuture);
// newFuture's lifetime is determined by taskFuture, which can't complete before oldFuture
// unless taskFuture is cancelled, in which case it falls back to oldFuture. This ensures that
Reported by PMD.
Line: 257
// Adding the listener to both futures guarantees that newFuture will aways be set. Adding to
// taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
// propagates cancellation if the callable has not yet been invoked.
outputFuture.addListener(listener, directExecutor());
taskFuture.addListener(listener, directExecutor());
return outputFuture;
}
Reported by PMD.
Line: 258
// taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
// propagates cancellation if the callable has not yet been invoked.
outputFuture.addListener(listener, directExecutor());
taskFuture.addListener(listener, directExecutor());
return outputFuture;
}
enum RunningState {
Reported by PMD.
Line: 287
* properties; for example, calling WeakReference.get() on Android will block during an
* otherwise-concurrent GC cycle.
*/
private static final class TaskNonReentrantExecutor extends AtomicReference<RunningState>
implements Executor, Runnable {
/**
* Used to update and read the latestTaskQueue field. Set to null once the runnable has been run
* or queued.
Reported by PMD.