The following issues were found
guava-testlib/src/com/google/common/testing/EquivalenceTester.java
5 issues
Line: 57
public final class EquivalenceTester<T> {
private static final int REPETITIONS = 3;
private final Equivalence<? super T> equivalence;
private final RelationshipTester<T> delegate;
private final List<T> items = Lists.newArrayList();
private EquivalenceTester(Equivalence<? super T> equivalence) {
this.equivalence = checkNotNull(equivalence);
Reported by PMD.
Line: 58
private static final int REPETITIONS = 3;
private final Equivalence<? super T> equivalence;
private final RelationshipTester<T> delegate;
private final List<T> items = Lists.newArrayList();
private EquivalenceTester(Equivalence<? super T> equivalence) {
this.equivalence = checkNotNull(equivalence);
this.delegate =
Reported by PMD.
Line: 59
private final Equivalence<? super T> equivalence;
private final RelationshipTester<T> delegate;
private final List<T> items = Lists.newArrayList();
private EquivalenceTester(Equivalence<? super T> equivalence) {
this.equivalence = checkNotNull(equivalence);
this.delegate =
new RelationshipTester<T>(equivalence, "equivalent", "hash", new ItemReporter());
Reported by PMD.
Line: 87
}
/** Run tests on equivalence methods, throwing a failure on an invalid test */
public EquivalenceTester<T> test() {
for (int run = 0; run < REPETITIONS; run++) {
testItems();
delegate.test();
}
return this;
Reported by PMD.
Line: 95
return this;
}
private void testItems() {
for (T item : items) {
/*
* TODO(cpovirk): consider no longer running these equivalent() tests on every Equivalence,
* since the Equivalence base type now implements this logic itself
*/
Reported by PMD.
guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java
5 issues
Line: 42
private static final long[] nonnegative = new long[ARRAY_SIZE];
private static final long[] longs = new long[ARRAY_SIZE];
@BeforeExperiment
void setUp() {
for (int i = 0; i < ARRAY_SIZE; i++) {
exponents[i] = randomExponent();
positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();
Reported by PMD.
Line: 46
void setUp() {
for (int i = 0; i < ARRAY_SIZE; i++) {
exponents[i] = randomExponent();
positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();
longs[i] = RANDOM_SOURCE.nextLong();
factorialArguments[i] = RANDOM_SOURCE.nextInt(30);
binomialArguments[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
int k = binomialArguments[i][1];
Reported by PMD.
Line: 47
for (int i = 0; i < ARRAY_SIZE; i++) {
exponents[i] = randomExponent();
positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();
longs[i] = RANDOM_SOURCE.nextLong();
factorialArguments[i] = RANDOM_SOURCE.nextInt(30);
binomialArguments[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
int k = binomialArguments[i][1];
binomialArguments[i][0] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials[k] - k) + k;
Reported by PMD.
Line: 108
@Benchmark
int isPrime(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
if (LongMath.isPrime(positive[j])) {
tmp++;
}
Reported by PMD.
Line: 112
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
if (LongMath.isPrime(positive[j])) {
tmp++;
}
}
return tmp;
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java
5 issues
Line: 39
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListRemoveAllTester<E> extends AbstractListTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
E duplicate = arrayAndDuplicate.duplicate;
Reported by PMD.
Line: 41
public class ListRemoveAllTester<E> extends AbstractListTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
E duplicate = arrayAndDuplicate.duplicate;
assertTrue(
Reported by PMD.
Line: 43
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
E duplicate = arrayAndDuplicate.duplicate;
assertTrue(
"removeAll(intersectingCollection) should return true",
getList().removeAll(MinimalCollection.of(duplicate)));
Reported by PMD.
Line: 48
assertTrue(
"removeAll(intersectingCollection) should return true",
getList().removeAll(MinimalCollection.of(duplicate)));
assertFalse(
"after removeAll(e), a collection should not contain e even "
+ "if it initially contained e more than once.",
getList().contains(duplicate));
}
Reported by PMD.
Line: 52
assertFalse(
"after removeAll(e), a collection should not contain e even "
+ "if it initially contained e more than once.",
getList().contains(duplicate));
}
// All other cases are covered by CollectionRemoveAllTester.
}
Reported by PMD.
android/guava-tests/benchmark/com/google/common/collect/SetCreationBenchmark.java
5 issues
Line: 35
"3", "6", "11", "23", "45", "91", "181", "362", "724", "1448", "2896", "5793", "11585", "23170",
"46341", "92682", "185364", "370728", "741455", "1482910", "2965821", "5931642"
})
private int size;
// "" means no fixed seed
@Param("1234")
private SpecialRandom random;
Reported by PMD.
Line: 39
// "" means no fixed seed
@Param("1234")
private SpecialRandom random;
@Param({"ImmutableSetImpl", "HashSetImpl"})
private SetImpl impl;
// the following must be set during setUp
Reported by PMD.
Line: 42
private SpecialRandom random;
@Param({"ImmutableSetImpl", "HashSetImpl"})
private SetImpl impl;
// the following must be set during setUp
private CollectionBenchmarkSampleData sampleData;
@BeforeExperiment
Reported by PMD.
Line: 45
private SetImpl impl;
// the following must be set during setUp
private CollectionBenchmarkSampleData sampleData;
@BeforeExperiment
void setUp() {
sampleData = new CollectionBenchmarkSampleData(true, random, 0.8, size);
}
Reported by PMD.
Line: 47
// the following must be set during setUp
private CollectionBenchmarkSampleData sampleData;
@BeforeExperiment
void setUp() {
sampleData = new CollectionBenchmarkSampleData(true, random, 0.8, size);
}
@Benchmark
Reported by PMD.
android/guava-tests/test/com/google/common/math/MathBenchmarking.java
5 issues
Line: 31
*
* @author Louis Wasserman
*/
final class MathBenchmarking {
static final int ARRAY_SIZE = 0x10000;
static final int ARRAY_MASK = 0x0ffff;
static final Random RANDOM_SOURCE = new Random(314159265358979L);
static final int MAX_EXPONENT = 100;
Reported by PMD.
Line: 86
BigInteger result;
do {
result = randomNonNegativeBigInteger(numBits);
} while (result.signum() == 0);
return result;
}
/**
* Generates a number in [0, 2^numBits) with an exponential distribution. The floor of the log2 of
Reported by PMD.
Line: 110
*/
static BigInteger randomNonZeroBigInteger(int numBits) {
BigInteger result = randomPositiveBigInteger(numBits);
return RANDOM_SOURCE.nextBoolean() ? result : result.negate();
}
/**
* Chooses a number in (-2^numBits, 2^numBits) at random, with density concentrated in numbers of
* lower magnitude.
Reported by PMD.
Line: 122
if (RANDOM_SOURCE.nextBoolean()) {
return randomNonNegativeBigInteger(numBits);
}
BigInteger neg = randomNonNegativeBigInteger(numBits).negate();
if (neg.signum() != 0) {
return neg;
}
}
}
Reported by PMD.
Line: 123
return randomNonNegativeBigInteger(numBits);
}
BigInteger neg = randomNonNegativeBigInteger(numBits).negate();
if (neg.signum() != 0) {
return neg;
}
}
}
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java
5 issues
Line: 40
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetAddTester<E> extends AbstractSetTester<E> {
@CollectionFeature.Require(SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAdd_supportedPresent() {
assertFalse("add(present) should return false", getSet().add(e0()));
expectUnchanged();
}
Reported by PMD.
Line: 43
@CollectionFeature.Require(SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAdd_supportedPresent() {
assertFalse("add(present) should return false", getSet().add(e0()));
expectUnchanged();
}
@CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 47
expectUnchanged();
}
@CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testAdd_supportedNullPresent() {
E[] array = createArrayWithNullElement();
collection = getSubjectGenerator().create(array);
assertFalse("add(nullPresent) should return false", getSet().add(null));
Reported by PMD.
Line: 51
@CollectionSize.Require(absent = ZERO)
public void testAdd_supportedNullPresent() {
E[] array = createArrayWithNullElement();
collection = getSubjectGenerator().create(array);
assertFalse("add(nullPresent) should return false", getSet().add(null));
expectContents(array);
}
/**
Reported by PMD.
Line: 52
public void testAdd_supportedNullPresent() {
E[] array = createArrayWithNullElement();
collection = getSubjectGenerator().create(array);
assertFalse("add(nullPresent) should return false", getSet().add(null));
expectContents(array);
}
/**
* Returns the {@link Method} instance for {@link #testAdd_supportedNullPresent()} so that tests
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java
5 issues
Line: 37
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetMultimapPutAllTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllHandlesDuplicates() {
@SuppressWarnings("unchecked")
List<V> valuesToPut = Arrays.asList(v0(), v1(), v0());
for (K k : sampleKeys()) {
Reported by PMD.
Line: 45
for (K k : sampleKeys()) {
resetContainer();
Set<V> expectedValues = copyToSet(multimap().get(k));
multimap().putAll(k, valuesToPut);
expectedValues.addAll(valuesToPut);
assertGet(k, expectedValues);
Reported by PMD.
Line: 47
Set<V> expectedValues = copyToSet(multimap().get(k));
multimap().putAll(k, valuesToPut);
expectedValues.addAll(valuesToPut);
assertGet(k, expectedValues);
}
}
Reported by PMD.
Line: 48
Set<V> expectedValues = copyToSet(multimap().get(k));
multimap().putAll(k, valuesToPut);
expectedValues.addAll(valuesToPut);
assertGet(k, expectedValues);
}
}
}
Reported by PMD.
Line: 40
@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllHandlesDuplicates() {
@SuppressWarnings("unchecked")
List<V> valuesToPut = Arrays.asList(v0(), v1(), v0());
for (K k : sampleKeys()) {
resetContainer();
Set<V> expectedValues = copyToSet(multimap().get(k));
Reported by PMD.
android/guava-testlib/src/com/google/common/testing/ClusterException.java
5 issues
Line: 62
* @author Luiz-Otavio Zorzella
*/
@GwtCompatible
final class ClusterException extends RuntimeException {
public final Collection<? extends Throwable> exceptions;
private ClusterException(Collection<? extends Throwable> exceptions) {
super(
Reported by PMD.
Line: 64
@GwtCompatible
final class ClusterException extends RuntimeException {
public final Collection<? extends Throwable> exceptions;
private ClusterException(Collection<? extends Throwable> exceptions) {
super(
exceptions.size() + " exceptions were thrown. The first exception is listed as a cause.",
exceptions.iterator().next());
Reported by PMD.
Line: 100
* @throws IllegalArgumentException if {@code exceptions} is empty
*/
public static RuntimeException create(Collection<? extends Throwable> exceptions) {
if (exceptions.size() == 0) {
throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
}
if (exceptions.size() == 1) {
Throwable temp = exceptions.iterator().next();
if (temp instanceof RuntimeException) {
Reported by PMD.
Line: 103
if (exceptions.size() == 0) {
throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
}
if (exceptions.size() == 1) {
Throwable temp = exceptions.iterator().next();
if (temp instanceof RuntimeException) {
return (RuntimeException) temp;
} else {
return new RuntimeException(temp);
Reported by PMD.
Line: 104
throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
}
if (exceptions.size() == 1) {
Throwable temp = exceptions.iterator().next();
if (temp instanceof RuntimeException) {
return (RuntimeException) temp;
} else {
return new RuntimeException(temp);
}
Reported by PMD.
android/guava-testlib/src/com/google/common/collect/testing/google/MultisetContainsTester.java
5 issues
Line: 32
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetContainsTester<E> extends AbstractMultisetTester<E> {
@CollectionSize.Require(absent = ZERO)
public void testContainsAllMultisetIgnoresFrequency() {
assertTrue(getMultiset().containsAll(getSubjectGenerator().create(e0(), e0(), e0())));
}
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 34
public class MultisetContainsTester<E> extends AbstractMultisetTester<E> {
@CollectionSize.Require(absent = ZERO)
public void testContainsAllMultisetIgnoresFrequency() {
assertTrue(getMultiset().containsAll(getSubjectGenerator().create(e0(), e0(), e0())));
}
@CollectionSize.Require(absent = ZERO)
public void testContainsAllListIgnoresFrequency() {
assertTrue(getMultiset().containsAll(Arrays.asList(e0(), e0(), e0())));
Reported by PMD.
Line: 34
public class MultisetContainsTester<E> extends AbstractMultisetTester<E> {
@CollectionSize.Require(absent = ZERO)
public void testContainsAllMultisetIgnoresFrequency() {
assertTrue(getMultiset().containsAll(getSubjectGenerator().create(e0(), e0(), e0())));
}
@CollectionSize.Require(absent = ZERO)
public void testContainsAllListIgnoresFrequency() {
assertTrue(getMultiset().containsAll(Arrays.asList(e0(), e0(), e0())));
Reported by PMD.
Line: 37
assertTrue(getMultiset().containsAll(getSubjectGenerator().create(e0(), e0(), e0())));
}
@CollectionSize.Require(absent = ZERO)
public void testContainsAllListIgnoresFrequency() {
assertTrue(getMultiset().containsAll(Arrays.asList(e0(), e0(), e0())));
}
}
Reported by PMD.
Line: 39
@CollectionSize.Require(absent = ZERO)
public void testContainsAllListIgnoresFrequency() {
assertTrue(getMultiset().containsAll(Arrays.asList(e0(), e0(), e0())));
}
}
Reported by PMD.
android/guava-tests/test/com/google/common/graph/PackageSanityTests.java
5 issues
Line: 61
setDefault(EndpointPair.class, EndpointPair.ordered("A", "B"));
}
@Override
public void testNulls() throws Exception {
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
Reported by PMD.
Line: 66
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
.that(e)
.hasCauseThat()
.hasMessageThat()
.contains(ERROR_ELEMENT_NOT_IN_GRAPH);
}
Reported by PMD.
Line: 66
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
.that(e)
.hasCauseThat()
.hasMessageThat()
.contains(ERROR_ELEMENT_NOT_IN_GRAPH);
}
Reported by PMD.
Line: 66
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
.that(e)
.hasCauseThat()
.hasMessageThat()
.contains(ERROR_ELEMENT_NOT_IN_GRAPH);
}
Reported by PMD.
Line: 66
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
.that(e)
.hasCauseThat()
.hasMessageThat()
.contains(ERROR_ELEMENT_NOT_IN_GRAPH);
}
Reported by PMD.