The following issues were found
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.
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.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveIfTester.java
7 issues
Line: 45
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionRemoveIfTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testRemoveIf_alwaysFalse() {
assertFalse("removeIf(x -> false) should return false", collection.removeIf(x -> false));
expectUnchanged();
}
Reported by PMD.
Line: 51
expectUnchanged();
}
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_sometimesTrue() {
assertTrue(
"removeIf(isEqual(present)) should return true",
collection.removeIf(Predicate.isEqual(samples.e0())));
Reported by PMD.
Line: 60
expectMissing(samples.e0());
}
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_allPresent() {
assertTrue("removeIf(x -> true) should return true", collection.removeIf(x -> true));
expectContents();
}
Reported by PMD.
Line: 67
expectContents();
}
@CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(SEVERAL)
public void testRemoveIfSomeMatchesConcurrentWithIteration() {
try {
Iterator<E> iterator = collection.iterator();
assertTrue(collection.removeIf(Predicate.isEqual(samples.e0())));
Reported by PMD.
Line: 80
}
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
public void testRemoveIf_unsupportedEmptyCollection() {
try {
assertFalse(
"removeIf(Predicate) should return false or throw " + "UnsupportedOperationException",
Reported by PMD.
Line: 90
x -> {
throw new AssertionError("predicate should never be called");
}));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
Reported by PMD.
Line: 95
expectUnchanged();
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_alwaysTrueUnsupported() {
try {
collection.removeIf(x -> true);
fail("removeIf(x -> true) should throw " + "UnsupportedOperationException");
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java
7 issues
Line: 41
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClear() {
collection.clear();
assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
assertEquals(0, collection.size());
assertFalse(collection.iterator().hasNext());
Reported by PMD.
Line: 42
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClear() {
collection.clear();
assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
assertEquals(0, collection.size());
assertFalse(collection.iterator().hasNext());
}
Reported by PMD.
Line: 46
collection.clear();
assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
assertEquals(0, collection.size());
assertFalse(collection.iterator().hasNext());
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testClear_unsupported() {
Reported by PMD.
Line: 49
assertFalse(collection.iterator().hasNext());
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testClear_unsupported() {
try {
collection.clear();
fail(
Reported by PMD.
Line: 62
expectUnchanged();
}
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
public void testClear_unsupportedByEmptyCollection() {
try {
collection.clear();
} catch (UnsupportedOperationException tolerated) {
Reported by PMD.
Line: 67
public void testClear_unsupportedByEmptyCollection() {
try {
collection.clear();
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
Reported by PMD.
Line: 72
expectUnchanged();
}
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(SEVERAL)
public void testClearConcurrentWithIteration() {
try {
Iterator<E> iterator = collection.iterator();
collection.clear();
Reported by PMD.
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-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java
6 issues
Line: 39
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class QueueElementTester<E> extends AbstractQueueTester<E> {
@CollectionSize.Require(ZERO)
public void testElement_empty() {
try {
getQueue().element();
fail("emptyQueue.element() should throw");
} catch (NoSuchElementException expected) {
Reported by PMD.
Line: 42
@CollectionSize.Require(ZERO)
public void testElement_empty() {
try {
getQueue().element();
fail("emptyQueue.element() should throw");
} catch (NoSuchElementException expected) {
}
expectUnchanged();
}
Reported by PMD.
Line: 49
expectUnchanged();
}
@CollectionSize.Require(ONE)
public void testElement_size1() {
assertEquals("size1Queue.element() should return first element", e0(), getQueue().element());
expectUnchanged();
}
Reported by PMD.
Line: 51
@CollectionSize.Require(ONE)
public void testElement_size1() {
assertEquals("size1Queue.element() should return first element", e0(), getQueue().element());
expectUnchanged();
}
@CollectionFeature.Require(KNOWN_ORDER)
@CollectionSize.Require(SEVERAL)
Reported by PMD.
Line: 55
expectUnchanged();
}
@CollectionFeature.Require(KNOWN_ORDER)
@CollectionSize.Require(SEVERAL)
public void testElement_sizeMany() {
assertEquals("sizeManyQueue.element() should return first element", e0(), getQueue().element());
expectUnchanged();
}
Reported by PMD.
Line: 58
@CollectionFeature.Require(KNOWN_ORDER)
@CollectionSize.Require(SEVERAL)
public void testElement_sizeMany() {
assertEquals("sizeManyQueue.element() should return first element", e0(), getQueue().element());
expectUnchanged();
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java
6 issues
Line: 42
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionToStringTester<E> extends AbstractCollectionTester<E> {
public void testToString_minimal() {
assertNotNull("toString() should not return null", collection.toString());
}
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
Reported by PMD.
Line: 46
assertNotNull("toString() should not return null", collection.toString());
}
@CollectionSize.Require(ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size0() {
assertEquals("emptyCollection.toString should return []", "[]", collection.toString());
}
Reported by PMD.
Line: 52
assertEquals("emptyCollection.toString should return []", "[]", collection.toString());
}
@CollectionSize.Require(ONE)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size1() {
assertEquals(
"size1Collection.toString should return [{element}]",
"[" + e0() + "]",
Reported by PMD.
Line: 61
collection.toString());
}
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(value = KNOWN_ORDER, absent = NON_STANDARD_TOSTRING)
public void testToString_sizeSeveral() {
String expected = Helpers.copyToList(getOrderedElements()).toString();
assertEquals("collection.toString() incorrect", expected, collection.toString());
}
Reported by PMD.
Line: 64
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(value = KNOWN_ORDER, absent = NON_STANDARD_TOSTRING)
public void testToString_sizeSeveral() {
String expected = Helpers.copyToList(getOrderedElements()).toString();
assertEquals("collection.toString() incorrect", expected, collection.toString());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
Reported by PMD.
Line: 68
assertEquals("collection.toString() incorrect", expected, collection.toString());
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testToString_null() {
initCollectionWithNullElement();
testToString_minimal();
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionStreamTester.java
6 issues
Line: 42
* that corresponds to the expected elements.
*/
@CollectionFeature.Require(absent = KNOWN_ORDER)
public void testStreamToArrayUnknownOrder() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
Helpers.assertEqualIgnoringOrder(
getSampleElements(), Arrays.asList(collection.stream().toArray()));
}
Reported by PMD.
Line: 46
public void testStreamToArrayUnknownOrder() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
Helpers.assertEqualIgnoringOrder(
getSampleElements(), Arrays.asList(collection.stream().toArray()));
}
}
@CollectionFeature.Require(KNOWN_ORDER)
public void testStreamToArrayKnownOrder() {
Reported by PMD.
Line: 50
}
}
@CollectionFeature.Require(KNOWN_ORDER)
public void testStreamToArrayKnownOrder() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
assertEquals(getOrderedElements(), Arrays.asList(collection.stream().toArray()));
}
}
Reported by PMD.
Line: 53
@CollectionFeature.Require(KNOWN_ORDER)
public void testStreamToArrayKnownOrder() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
assertEquals(getOrderedElements(), Arrays.asList(collection.stream().toArray()));
}
}
public void testStreamCount() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
Reported by PMD.
Line: 57
}
}
public void testStreamCount() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
assertEquals(getNumElements(), collection.stream().count());
}
}
}
Reported by PMD.
Line: 59
public void testStreamCount() {
synchronized (collection) { // to allow Collections.synchronized* tests to pass
assertEquals(getNumElements(), collection.stream().count());
}
}
}
Reported by PMD.
guava-tests/test/com/google/common/cache/LongAdderTest.java
6 issues
Line: 29
* version, which checks package-private methods that we don't want to have to annotate as {@code
* Nullable} because we don't want diffs from jsr166e.
*/
public void testNulls() {}
public void testOverflows() {
LongAdder longAdder = new LongAdder();
longAdder.add(Long.MAX_VALUE);
assertThat(longAdder.sum()).isEqualTo(Long.MAX_VALUE);
Reported by PMD.
Line: 29
* version, which checks package-private methods that we don't want to have to annotate as {@code
* Nullable} because we don't want diffs from jsr166e.
*/
public void testNulls() {}
public void testOverflows() {
LongAdder longAdder = new LongAdder();
longAdder.add(Long.MAX_VALUE);
assertThat(longAdder.sum()).isEqualTo(Long.MAX_VALUE);
Reported by PMD.
Line: 31
*/
public void testNulls() {}
public void testOverflows() {
LongAdder longAdder = new LongAdder();
longAdder.add(Long.MAX_VALUE);
assertThat(longAdder.sum()).isEqualTo(Long.MAX_VALUE);
longAdder.add(1);
// silently overflows; is this a bug?
Reported by PMD.
Line: 31
*/
public void testNulls() {}
public void testOverflows() {
LongAdder longAdder = new LongAdder();
longAdder.add(Long.MAX_VALUE);
assertThat(longAdder.sum()).isEqualTo(Long.MAX_VALUE);
longAdder.add(1);
// silently overflows; is this a bug?
Reported by PMD.
Line: 34
public void testOverflows() {
LongAdder longAdder = new LongAdder();
longAdder.add(Long.MAX_VALUE);
assertThat(longAdder.sum()).isEqualTo(Long.MAX_VALUE);
longAdder.add(1);
// silently overflows; is this a bug?
// See https://github.com/google/guava/issues/3503
assertThat(longAdder.sum()).isEqualTo(-9223372036854775808L);
}
Reported by PMD.
Line: 38
longAdder.add(1);
// silently overflows; is this a bug?
// See https://github.com/google/guava/issues/3503
assertThat(longAdder.sum()).isEqualTo(-9223372036854775808L);
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/ListReplaceAllTester.java
6 issues
Line: 38
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListReplaceAllTester<E> extends AbstractListTester<E> {
@ListFeature.Require(SUPPORTS_SET)
public void testReplaceAll() {
getList().replaceAll(e -> samples.e3());
expectContents(Collections.nCopies(getNumElements(), samples.e3()));
}
Reported by PMD.
Line: 40
public class ListReplaceAllTester<E> extends AbstractListTester<E> {
@ListFeature.Require(SUPPORTS_SET)
public void testReplaceAll() {
getList().replaceAll(e -> samples.e3());
expectContents(Collections.nCopies(getNumElements(), samples.e3()));
}
@ListFeature.Require(SUPPORTS_SET)
public void testReplaceAll_changesSome() {
Reported by PMD.
Line: 44
expectContents(Collections.nCopies(getNumElements(), samples.e3()));
}
@ListFeature.Require(SUPPORTS_SET)
public void testReplaceAll_changesSome() {
getList().replaceAll(e -> e.equals(samples.e0()) ? samples.e3() : e);
E[] expected = createSamplesArray();
for (int i = 0; i < expected.length; i++) {
if (expected[i].equals(samples.e0())) {
Reported by PMD.
Line: 46
@ListFeature.Require(SUPPORTS_SET)
public void testReplaceAll_changesSome() {
getList().replaceAll(e -> e.equals(samples.e0()) ? samples.e3() : e);
E[] expected = createSamplesArray();
for (int i = 0; i < expected.length; i++) {
if (expected[i].equals(samples.e0())) {
expected[i] = samples.e3();
}
Reported by PMD.
Line: 56
expectContents(expected);
}
@CollectionSize.Require(absent = ZERO)
@ListFeature.Require(absent = SUPPORTS_SET)
public void testReplaceAll_unsupported() {
try {
getList().replaceAll(e -> e);
fail("replaceAll() should throw UnsupportedOperationException");
Reported by PMD.
Line: 60
@ListFeature.Require(absent = SUPPORTS_SET)
public void testReplaceAll_unsupported() {
try {
getList().replaceAll(e -> e);
fail("replaceAll() should throw UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
Reported by PMD.