The following issues were found
android/guava-tests/benchmark/com/google/common/util/concurrent/CycleDetectingLockFactoryBenchmark.java
7 issues
Line: 33
public class CycleDetectingLockFactoryBenchmark {
@Param({"2", "3", "4", "5", "10"})
int lockNestingDepth;
CycleDetectingLockFactory factory;
private Lock[] plainLocks;
private Lock[] detectingLocks;
Reported by PMD.
Line: 35
@Param({"2", "3", "4", "5", "10"})
int lockNestingDepth;
CycleDetectingLockFactory factory;
private Lock[] plainLocks;
private Lock[] detectingLocks;
@BeforeExperiment
void setUp() throws Exception {
Reported by PMD.
Line: 36
int lockNestingDepth;
CycleDetectingLockFactory factory;
private Lock[] plainLocks;
private Lock[] detectingLocks;
@BeforeExperiment
void setUp() throws Exception {
this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
Reported by PMD.
Line: 37
CycleDetectingLockFactory factory;
private Lock[] plainLocks;
private Lock[] detectingLocks;
@BeforeExperiment
void setUp() throws Exception {
this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
this.plainLocks = new Lock[lockNestingDepth];
Reported by PMD.
Line: 39
private Lock[] plainLocks;
private Lock[] detectingLocks;
@BeforeExperiment
void setUp() throws Exception {
this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
this.plainLocks = new Lock[lockNestingDepth];
for (int i = 0; i < lockNestingDepth; i++) {
plainLocks[i] = new ReentrantLock();
Reported by PMD.
Line: 40
private Lock[] detectingLocks;
@BeforeExperiment
void setUp() throws Exception {
this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
this.plainLocks = new Lock[lockNestingDepth];
for (int i = 0; i < lockNestingDepth; i++) {
plainLocks[i] = new ReentrantLock();
}
Reported by PMD.
Line: 81
private static void lockAndUnlockNested(Lock[] locks, int reps) {
for (int i = 0; i < reps; i++) {
for (int j = 0; j < locks.length; j++) {
locks[j].lock();
}
for (int j = locks.length - 1; j >= 0; j--) {
locks[j].unlock();
}
Reported by PMD.
android/guava-tests/test/com/google/common/collect/ForwardingSortedSetTest.java
7 issues
Line: 41
* @author Louis Wasserman
*/
public class ForwardingSortedSetTest extends TestCase {
static class StandardImplForwardingSortedSet<T> extends ForwardingSortedSet<T> {
private final SortedSet<T> backingSortedSet;
StandardImplForwardingSortedSet(SortedSet<T> backingSortedSet) {
this.backingSortedSet = backingSortedSet;
}
Reported by PMD.
Line: 42
*/
public class ForwardingSortedSetTest extends TestCase {
static class StandardImplForwardingSortedSet<T> extends ForwardingSortedSet<T> {
private final SortedSet<T> backingSortedSet;
StandardImplForwardingSortedSet(SortedSet<T> backingSortedSet) {
this.backingSortedSet = backingSortedSet;
}
Reported by PMD.
Line: 119
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingSortedSetTest.class);
suite.addTest(
SortedSetTestSuiteBuilder.using(
Reported by PMD.
Line: 147
return suite;
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
SortedSet.class,
new Function<SortedSet, SortedSet>() {
Reported by PMD.
Line: 148
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
SortedSet.class,
new Function<SortedSet, SortedSet>() {
@Override
Reported by PMD.
Line: 160
});
}
public void testEquals() {
SortedSet<String> set1 = ImmutableSortedSet.of("one");
SortedSet<String> set2 = ImmutableSortedSet.of("two");
new EqualsTester()
.addEqualityGroup(set1, wrap(set1), wrap(set1))
.addEqualityGroup(set2, wrap(set2))
Reported by PMD.
Line: 160
});
}
public void testEquals() {
SortedSet<String> set1 = ImmutableSortedSet.of("one");
SortedSet<String> set2 = ImmutableSortedSet.of("two");
new EqualsTester()
.addEqualityGroup(set1, wrap(set1), wrap(set1))
.addEqualityGroup(set2, wrap(set2))
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java
7 issues
Line: 38
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetHashCodeTester<E> extends AbstractSetTester<E> {
public void testHashCode() {
int expectedHashCode = 0;
for (E element : getSampleElements()) {
expectedHashCode += ((element == null) ? 0 : element.hashCode());
}
assertEquals(
Reported by PMD.
Line: 46
assertEquals(
"A Set's hashCode() should be the sum of those of its elements.",
expectedHashCode,
getSet().hashCode());
}
@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testHashCode_containingNull() {
Reported by PMD.
Line: 49
getSet().hashCode());
}
@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testHashCode_containingNull() {
Collection<E> elements = getSampleElements(getNumElements() - 1);
int expectedHashCode = 0;
for (E element : elements) {
Reported by PMD.
Line: 58
expectedHashCode += ((element == null) ? 0 : element.hashCode());
}
elements.add(null);
collection = getSubjectGenerator().create(elements.toArray());
assertEquals(
"A Set's hashCode() should be the sum of those of its elements (with "
+ "a null element counting as having a hash of zero).",
expectedHashCode,
Reported by PMD.
Line: 59
}
elements.add(null);
collection = getSubjectGenerator().create(elements.toArray());
assertEquals(
"A Set's hashCode() should be the sum of those of its elements (with "
+ "a null element counting as having a hash of zero).",
expectedHashCode,
getSet().hashCode());
Reported by PMD.
Line: 59
}
elements.add(null);
collection = getSubjectGenerator().create(elements.toArray());
assertEquals(
"A Set's hashCode() should be the sum of those of its elements (with "
+ "a null element counting as having a hash of zero).",
expectedHashCode,
getSet().hashCode());
Reported by PMD.
Line: 64
"A Set's hashCode() should be the sum of those of its elements (with "
+ "a null element counting as having a hash of zero).",
expectedHashCode,
getSet().hashCode());
}
/**
* Returns the {@link Method} instances for the test methods in this class which call {@code
* hashCode()} on the set values so that set tests on unhashable objects can suppress it with
Reported by PMD.
android/guava-tests/test/com/google/common/collect/ForwardingListTest.java
7 issues
Line: 42
* @author Louis Wasserman
*/
public class ForwardingListTest extends TestCase {
static final class StandardImplForwardingList<T> extends ForwardingList<T> {
private final List<T> backingList;
StandardImplForwardingList(List<T> backingList) {
this.backingList = backingList;
}
Reported by PMD.
Line: 43
*/
public class ForwardingListTest extends TestCase {
static final class StandardImplForwardingList<T> extends ForwardingList<T> {
private final List<T> backingList;
StandardImplForwardingList(List<T> backingList) {
this.backingList = backingList;
}
Reported by PMD.
Line: 155
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingListTest.class);
suite.addTest(
ListTestSuiteBuilder.using(
Reported by PMD.
Line: 190
return suite;
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
List.class,
new Function<List, List>() {
Reported by PMD.
Line: 191
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
List.class,
new Function<List, List>() {
@Override
Reported by PMD.
Line: 203
});
}
public void testEquals() {
List<String> list1 = ImmutableList.of("one");
List<String> list2 = ImmutableList.of("two");
new EqualsTester()
.addEqualityGroup(list1, wrap(list1), wrap(list1))
.addEqualityGroup(list2, wrap(list2))
Reported by PMD.
Line: 203
});
}
public void testEquals() {
List<String> list1 = ImmutableList.of("one");
List<String> list2 = ImmutableList.of("two");
new EqualsTester()
.addEqualityGroup(list1, wrap(list1), wrap(list1))
.addEqualityGroup(list2, wrap(list2))
Reported by PMD.
android/guava-tests/benchmark/com/google/common/cache/ChainBenchmark.java
7 issues
Line: 32
public class ChainBenchmark {
@Param({"1", "2", "3", "4", "5", "6"})
int length;
private Segment<Object, Object> segment;
private ReferenceEntry<Object, Object> head;
private ReferenceEntry<Object, Object> chain;
Reported by PMD.
Line: 34
@Param({"1", "2", "3", "4", "5", "6"})
int length;
private Segment<Object, Object> segment;
private ReferenceEntry<Object, Object> head;
private ReferenceEntry<Object, Object> chain;
@SuppressWarnings("GuardedBy")
@BeforeExperiment
Reported by PMD.
Line: 35
int length;
private Segment<Object, Object> segment;
private ReferenceEntry<Object, Object> head;
private ReferenceEntry<Object, Object> chain;
@SuppressWarnings("GuardedBy")
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 36
private Segment<Object, Object> segment;
private ReferenceEntry<Object, Object> head;
private ReferenceEntry<Object, Object> chain;
@SuppressWarnings("GuardedBy")
@BeforeExperiment
void setUp() {
LocalCache<Object, Object> cache =
Reported by PMD.
Line: 38
private ReferenceEntry<Object, Object> head;
private ReferenceEntry<Object, Object> chain;
@SuppressWarnings("GuardedBy")
@BeforeExperiment
void setUp() {
LocalCache<Object, Object> cache =
new LocalCache<>(CacheBuilder.newBuilder().concurrencyLevel(1), null);
segment = cache.segments[0];
Reported by PMD.
Line: 44
LocalCache<Object, Object> cache =
new LocalCache<>(CacheBuilder.newBuilder().concurrencyLevel(1), null);
segment = cache.segments[0];
chain = null;
for (int i = 0; i < length; i++) {
Object key = new Object();
// TODO(b/145386688): This access should be guarded by 'this.segment', which is not currently
// held
chain = segment.newEntry(key, cache.hash(key), chain);
Reported by PMD.
Line: 46
segment = cache.segments[0];
chain = null;
for (int i = 0; i < length; i++) {
Object key = new Object();
// TODO(b/145386688): This access should be guarded by 'this.segment', which is not currently
// held
chain = segment.newEntry(key, cache.hash(key), chain);
if (i == 0) {
head = chain;
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapTestSuiteBuilder.java
7 issues
Line: 55
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
testers.add(SetMultimapAsMapTester.class);
testers.add(SetMultimapEqualsTester.class);
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
Reported by PMD.
Line: 56
protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
testers.add(SetMultimapAsMapTester.class);
testers.add(SetMultimapEqualsTester.class);
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
Reported by PMD.
Line: 57
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
testers.add(SetMultimapAsMapTester.class);
testers.add(SetMultimapEqualsTester.class);
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
return testers;
Reported by PMD.
Line: 58
testers.add(SetMultimapAsMapTester.class);
testers.add(SetMultimapEqualsTester.class);
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
return testers;
}
Reported by PMD.
Line: 59
testers.add(SetMultimapEqualsTester.class);
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
return testers;
}
Reported by PMD.
Line: 60
testers.add(SetMultimapPutTester.class);
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
return testers;
}
@Override
Reported by PMD.
Line: 61
testers.add(SetMultimapPutAllTester.class);
testers.add(SetMultimapReplaceValuesTester.class);
testers.add(SortedSetMultimapAsMapTester.class);
testers.add(SortedSetMultimapGetTester.class);
return testers;
}
@Override
TestSuite computeMultimapGetTestSuite(
Reported by PMD.
guava-gwt/src-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/InterruptibleTask.java
7 issues
Line: 33
}
try {
result = runInterruptibly();
} catch (Throwable t) {
error = t;
}
if (error == null) {
// The cast is safe because of the `run` and `error` checks.
afterRanInterruptiblySuccess(uncheckedCastNullableTToT(result));
Reported by PMD.
Line: 46
abstract boolean isDone();
abstract T runInterruptibly() throws Exception;
abstract void afterRanInterruptiblySuccess(T result);
abstract void afterRanInterruptiblyFailure(Throwable error);
Reported by PMD.
Line: 26
@Override
public void run() {
T result = null;
Throwable error = null;
if (isDone()) {
return;
}
try {
Reported by PMD.
Line: 26
@Override
public void run() {
T result = null;
Throwable error = null;
if (isDone()) {
return;
}
try {
Reported by PMD.
Line: 27
@Override
public void run() {
T result = null;
Throwable error = null;
if (isDone()) {
return;
}
try {
result = runInterruptibly();
Reported by PMD.
Line: 27
@Override
public void run() {
T result = null;
Throwable error = null;
if (isDone()) {
return;
}
try {
result = runInterruptibly();
Reported by PMD.
Line: 32
return;
}
try {
result = runInterruptibly();
} catch (Throwable t) {
error = t;
}
if (error == null) {
// The cast is safe because of the `run` and `error` checks.
Reported by PMD.
android/guava/src/com/google/common/util/concurrent/JdkFutureAdapters.java
7 issues
Line: 111
private static final Executor defaultAdapterExecutor =
Executors.newCachedThreadPool(threadFactory);
private final Executor adapterExecutor;
// The execution list to hold our listeners.
private final ExecutionList executionList = new ExecutionList();
// This allows us to only start up a thread waiting on the delegate future when the first
Reported by PMD.
Line: 114
private final Executor adapterExecutor;
// The execution list to hold our listeners.
private final ExecutionList executionList = new ExecutionList();
// This allows us to only start up a thread waiting on the delegate future when the first
// listener is added.
private final AtomicBoolean hasListeners = new AtomicBoolean(false);
Reported by PMD.
Line: 118
// This allows us to only start up a thread waiting on the delegate future when the first
// listener is added.
private final AtomicBoolean hasListeners = new AtomicBoolean(false);
// The delegate future.
private final Future<V> delegate;
ListenableFutureAdapter(Future<V> delegate) {
Reported by PMD.
Line: 121
private final AtomicBoolean hasListeners = new AtomicBoolean(false);
// The delegate future.
private final Future<V> delegate;
ListenableFutureAdapter(Future<V> delegate) {
this(delegate, defaultAdapterExecutor);
}
Reported by PMD.
Line: 121
private final AtomicBoolean hasListeners = new AtomicBoolean(false);
// The delegate future.
private final Future<V> delegate;
ListenableFutureAdapter(Future<V> delegate) {
this(delegate, defaultAdapterExecutor);
}
Reported by PMD.
Line: 163
* to return a proper ListenableFuture instead of using listenInPoolThread.
*/
getUninterruptibly(delegate);
} catch (Throwable e) {
// ExecutionException / CancellationException / RuntimeException / Error
// The task is presumably done, run the listeners.
}
executionList.execute();
}
Reported by PMD.
Line: 163
* to return a proper ListenableFuture instead of using listenInPoolThread.
*/
getUninterruptibly(delegate);
} catch (Throwable e) {
// ExecutionException / CancellationException / RuntimeException / Error
// The task is presumably done, run the listeners.
}
executionList.execute();
}
Reported by PMD.
android/guava/src/com/google/common/graph/MultiEdgesConnecting.java
7 issues
Line: 41
@ElementTypesAreNonnullByDefault
abstract class MultiEdgesConnecting<E> extends AbstractSet<E> {
private final Map<E, ?> outEdgeToNode;
private final Object targetNode;
MultiEdgesConnecting(Map<E, ?> outEdgeToNode, Object targetNode) {
this.outEdgeToNode = checkNotNull(outEdgeToNode);
this.targetNode = checkNotNull(targetNode);
Reported by PMD.
Line: 42
abstract class MultiEdgesConnecting<E> extends AbstractSet<E> {
private final Map<E, ?> outEdgeToNode;
private final Object targetNode;
MultiEdgesConnecting(Map<E, ?> outEdgeToNode, Object targetNode) {
this.outEdgeToNode = checkNotNull(outEdgeToNode);
this.targetNode = checkNotNull(targetNode);
}
Reported by PMD.
Line: 51
@Override
public UnmodifiableIterator<E> iterator() {
final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
return new AbstractIterator<E>() {
@Override
@CheckForNull
protected E computeNext() {
while (entries.hasNext()) {
Reported by PMD.
Line: 58
protected E computeNext() {
while (entries.hasNext()) {
Entry<E, ?> entry = entries.next();
if (targetNode.equals(entry.getValue())) {
return entry.getKey();
}
}
return endOfData();
}
Reported by PMD.
Line: 59
while (entries.hasNext()) {
Entry<E, ?> entry = entries.next();
if (targetNode.equals(entry.getValue())) {
return entry.getKey();
}
}
return endOfData();
}
};
Reported by PMD.
Line: 51
@Override
public UnmodifiableIterator<E> iterator() {
final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
return new AbstractIterator<E>() {
@Override
@CheckForNull
protected E computeNext() {
while (entries.hasNext()) {
Reported by PMD.
Line: 51
@Override
public UnmodifiableIterator<E> iterator() {
final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
return new AbstractIterator<E>() {
@Override
@CheckForNull
protected E computeNext() {
while (entries.hasNext()) {
Reported by PMD.
android/guava/src/com/google/common/util/concurrent/ForwardingFuture.java
7 issues
Line: 50
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return delegate().cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return delegate().isCancelled();
Reported by PMD.
Line: 55
@Override
public boolean isCancelled() {
return delegate().isCancelled();
}
@Override
public boolean isDone() {
return delegate().isDone();
Reported by PMD.
Line: 60
@Override
public boolean isDone() {
return delegate().isDone();
}
@Override
@ParametricNullness
public V get() throws InterruptedException, ExecutionException {
Reported by PMD.
Line: 66
@Override
@ParametricNullness
public V get() throws InterruptedException, ExecutionException {
return delegate().get();
}
@Override
@ParametricNullness
public V get(long timeout, TimeUnit unit)
Reported by PMD.
Line: 73
@ParametricNullness
public V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return delegate().get(timeout, unit);
}
// TODO(cpovirk): Use standard Javadoc form for SimpleForwarding* class and constructor
/**
* A simplified version of {@link ForwardingFuture} where subclasses can pass in an already
Reported by PMD.
Line: 85
*/
public abstract static class SimpleForwardingFuture<V extends @Nullable Object>
extends ForwardingFuture<V> {
private final Future<V> delegate;
protected SimpleForwardingFuture(Future<V> delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
Reported by PMD.
Line: 85
*/
public abstract static class SimpleForwardingFuture<V extends @Nullable Object>
extends ForwardingFuture<V> {
private final Future<V> delegate;
protected SimpleForwardingFuture(Future<V> delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
Reported by PMD.