The following issues were found
guava/src/com/google/common/collect/Interners.java
7 issues
Line: 44
* @since 21.0
*/
public static class InternerBuilder {
private final MapMaker mapMaker = new MapMaker();
private boolean strong = true;
private InternerBuilder() {}
/**
Reported by PMD.
Line: 45
*/
public static class InternerBuilder {
private final MapMaker mapMaker = new MapMaker();
private boolean strong = true;
private InternerBuilder() {}
/**
* Instructs the {@link InternerBuilder} to build a strong interner.
Reported by PMD.
Line: 45
*/
public static class InternerBuilder {
private final MapMaker mapMaker = new MapMaker();
private boolean strong = true;
private InternerBuilder() {}
/**
* Instructs the {@link InternerBuilder} to build a strong interner.
Reported by PMD.
Line: 116
@VisibleForTesting
static final class InternerImpl<E> implements Interner<E> {
// MapMaker is our friend, we know about this type
@VisibleForTesting final MapMakerInternalMap<E, Dummy, ?, ?> map;
private InternerImpl(MapMaker mapMaker) {
this.map =
MapMakerInternalMap.createWithDummyValues(mapMaker.keyEquivalence(Equivalence.equals()));
}
Reported by PMD.
Line: 130
@SuppressWarnings("rawtypes") // using raw types to avoid a bug in our nullness checker :(
InternalEntry entry = map.getEntry(sample);
if (entry != null) {
Object canonical = entry.getKey();
if (canonical != null) { // only matters if weak/soft keys are used
// The compiler would know this is safe if not for our use of raw types (see above).
@SuppressWarnings("unchecked")
E result = (E) canonical;
return result;
Reported by PMD.
Line: 143
Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
if (sneaky == null) {
return sample;
} else {
/* Someone beat us to it! Trying again...
*
* Technically this loop not guaranteed to terminate, so theoretically (extremely
* unlikely) this thread might starve, but even then, there is always going to be another
* thread doing progress here.
Reported by PMD.
Line: 166
private static class InternerFunction<E> implements Function<E, E> {
private final Interner<E> interner;
public InternerFunction(Interner<E> interner) {
this.interner = interner;
}
Reported by PMD.
guava/src/com/google/common/collect/StandardRowSortedTable.java
7 issues
Line: 75
*/
@Override
public SortedSet<R> rowKeySet() {
return (SortedSet<R>) rowMap().keySet();
}
/**
* {@inheritDoc}
*
Reported by PMD.
Line: 109
@Override
@CheckForNull
public Comparator<? super R> comparator() {
return sortedBackingMap().comparator();
}
@Override
public R firstKey() {
return sortedBackingMap().firstKey();
Reported by PMD.
Line: 114
@Override
public R firstKey() {
return sortedBackingMap().firstKey();
}
@Override
public R lastKey() {
return sortedBackingMap().lastKey();
Reported by PMD.
Line: 119
@Override
public R lastKey() {
return sortedBackingMap().lastKey();
}
@Override
public SortedMap<R, Map<C, V>> headMap(R toKey) {
checkNotNull(toKey);
Reported by PMD.
Line: 125
@Override
public SortedMap<R, Map<C, V>> headMap(R toKey) {
checkNotNull(toKey);
return new StandardRowSortedTable<R, C, V>(sortedBackingMap().headMap(toKey), factory)
.rowMap();
}
@Override
public SortedMap<R, Map<C, V>> subMap(R fromKey, R toKey) {
Reported by PMD.
Line: 133
public SortedMap<R, Map<C, V>> subMap(R fromKey, R toKey) {
checkNotNull(fromKey);
checkNotNull(toKey);
return new StandardRowSortedTable<R, C, V>(sortedBackingMap().subMap(fromKey, toKey), factory)
.rowMap();
}
@Override
public SortedMap<R, Map<C, V>> tailMap(R fromKey) {
Reported by PMD.
Line: 140
@Override
public SortedMap<R, Map<C, V>> tailMap(R fromKey) {
checkNotNull(fromKey);
return new StandardRowSortedTable<R, C, V>(sortedBackingMap().tailMap(fromKey), factory)
.rowMap();
}
}
private static final long serialVersionUID = 0;
Reported by PMD.
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.
guava/src/com/google/common/cache/ForwardingLoadingCache.java
7 issues
Line: 46
@Override
public V get(K key) throws ExecutionException {
return delegate().get(key);
}
@Override
public V getUnchecked(K key) {
return delegate().getUnchecked(key);
Reported by PMD.
Line: 51
@Override
public V getUnchecked(K key) {
return delegate().getUnchecked(key);
}
@Override
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
return delegate().getAll(keys);
Reported by PMD.
Line: 56
@Override
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
return delegate().getAll(keys);
}
@Override
public V apply(K key) {
return delegate().apply(key);
Reported by PMD.
Line: 61
@Override
public V apply(K key) {
return delegate().apply(key);
}
@Override
public void refresh(K key) {
delegate().refresh(key);
Reported by PMD.
Line: 66
@Override
public void refresh(K key) {
delegate().refresh(key);
}
/**
* A simplified version of {@link ForwardingLoadingCache} where subclasses can pass in an already
* constructed {@link LoadingCache} as the delegate.
Reported by PMD.
Line: 77
*/
public abstract static class SimpleForwardingLoadingCache<K, V>
extends ForwardingLoadingCache<K, V> {
private final LoadingCache<K, V> delegate;
protected SimpleForwardingLoadingCache(LoadingCache<K, V> delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
Reported by PMD.
Line: 77
*/
public abstract static class SimpleForwardingLoadingCache<K, V>
extends ForwardingLoadingCache<K, V> {
private final LoadingCache<K, V> delegate;
protected SimpleForwardingLoadingCache(LoadingCache<K, V> delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
Reported by PMD.
guava/src/com/google/common/collect/ImmutableCollection.java
7 issues
Line: 230
/** If this collection is backed by an array of its elements in insertion order, returns it. */
@CheckForNull
Object[] internalArray() {
return null;
}
/**
* If this collection is backed by an array of its elements in insertion order, returns the offset
Reported by PMD.
Line: 211
* nullness perspective. The signature below at least has the virtue of being relatively simple.
*/
@SuppressWarnings("nullness")
public final <T extends @Nullable Object> T[] toArray(T[] other) {
checkNotNull(other);
int size = size();
if (other.length < size) {
Object[] internal = internalArray();
Reported by PMD.
Line: 383
* offset. Returns {@code offset + size()}.
*/
@CanIgnoreReturnValue
int copyIntoArray(@Nullable Object[] dst, int offset) {
for (E e : this) {
dst[offset++] = e;
}
return offset;
}
Reported by PMD.
Line: 169
@ElementTypesAreNonnullByDefault
// TODO(kevinb): I think we should push everything down to "BaseImmutableCollection" or something,
// just to do everything we can to emphasize the "practically an interface" nature of this class.
public abstract class ImmutableCollection<E> extends AbstractCollection<E> implements Serializable {
/*
* We expect SIZED (and SUBSIZED, if applicable) to be added by the spliterator factory methods.
* These are properties of the collection as a whole; SIZED and SUBSIZED are more properties of
* the spliterator implementation.
*/
Reported by PMD.
Line: 222
}
other = ObjectArrays.newArray(other, size);
} else if (other.length > size) {
other[size] = null;
}
copyIntoArray(other, 0);
return other;
}
Reported by PMD.
Line: 262
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
public final boolean add(E e) {
throw new UnsupportedOperationException();
}
/**
Reported by PMD.
Line: 364
case 0:
return ImmutableList.of();
case 1:
return ImmutableList.of(iterator().next());
default:
return new RegularImmutableAsList<E>(this, toArray());
}
}
Reported by PMD.
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.
guava-tests/test/com/google/common/collect/ForwardingSetTest.java
7 issues
Line: 42
* @author Louis Wasserman
*/
public class ForwardingSetTest extends TestCase {
static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
private final Set<T> backingSet;
StandardImplForwardingSet(Set<T> backingSet) {
this.backingSet = backingSet;
}
Reported by PMD.
Line: 43
*/
public class ForwardingSetTest extends TestCase {
static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
private final Set<T> backingSet;
StandardImplForwardingSet(Set<T> backingSet) {
this.backingSet = backingSet;
}
Reported by PMD.
Line: 115
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingSetTest.class);
suite.addTest(
SetTestSuiteBuilder.using(
Reported by PMD.
Line: 148
return suite;
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
Set.class,
new Function<Set, Set>() {
Reported by PMD.
Line: 149
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testForwarding() {
new ForwardingWrapperTester()
.testForwarding(
Set.class,
new Function<Set, Set>() {
@Override
Reported by PMD.
Line: 161
});
}
public void testEquals() {
Set<String> set1 = ImmutableSet.of("one");
Set<String> set2 = ImmutableSet.of("two");
new EqualsTester()
.addEqualityGroup(set1, wrap(set1), wrap(set1))
.addEqualityGroup(set2, wrap(set2))
Reported by PMD.
Line: 161
});
}
public void testEquals() {
Set<String> set1 = ImmutableSet.of("one");
Set<String> set2 = ImmutableSet.of("two");
new EqualsTester()
.addEqualityGroup(set1, wrap(set1), wrap(set1))
.addEqualityGroup(set2, wrap(set2))
Reported by PMD.
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.
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.
guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java
7 issues
Line: 36
*/
public class IntMathBenchmark {
private static int[] exponent = new int[ARRAY_SIZE];
private static int[] factorial = new int[ARRAY_SIZE];
private static int[] binomial = new int[ARRAY_SIZE];
private static final int[] positive = new int[ARRAY_SIZE];
private static final int[] nonnegative = new int[ARRAY_SIZE];
private static final int[] ints = new int[ARRAY_SIZE];
Reported by PMD.
Line: 37
public class IntMathBenchmark {
private static int[] exponent = new int[ARRAY_SIZE];
private static int[] factorial = new int[ARRAY_SIZE];
private static int[] binomial = new int[ARRAY_SIZE];
private static final int[] positive = new int[ARRAY_SIZE];
private static final int[] nonnegative = new int[ARRAY_SIZE];
private static final int[] ints = new int[ARRAY_SIZE];
@BeforeExperiment
Reported by PMD.
Line: 42
private static final int[] nonnegative = new int[ARRAY_SIZE];
private static final int[] ints = new int[ARRAY_SIZE];
@BeforeExperiment
void setUp() {
for (int i = 0; i < ARRAY_SIZE; i++) {
exponent[i] = randomExponent();
factorial[i] = RANDOM_SOURCE.nextInt(50);
binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
Reported by PMD.
Line: 48
exponent[i] = randomExponent();
factorial[i] = RANDOM_SOURCE.nextInt(50);
binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
ints[i] = RANDOM_SOURCE.nextInt();
}
}
Reported by PMD.
Line: 49
factorial[i] = RANDOM_SOURCE.nextInt(50);
binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
ints[i] = RANDOM_SOURCE.nextInt();
}
}
@Benchmark
Reported by PMD.
Line: 106
@Benchmark
int isPrime(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
if (IntMath.isPrime(positive[j])) {
tmp++;
}
Reported by PMD.
Line: 110
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
if (IntMath.isPrime(positive[j])) {
tmp++;
}
}
return tmp;
}
}
Reported by PMD.