The following issues were found
guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java
6 issues
Line: 41
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionCreationTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testCreateWithNull_supported() {
E[] array = createArrayWithNullElement();
collection = getSubjectGenerator().create(array);
expectContents(array);
Reported by PMD.
Line: 45
@CollectionSize.Require(absent = ZERO)
public void testCreateWithNull_supported() {
E[] array = createArrayWithNullElement();
collection = getSubjectGenerator().create(array);
expectContents(array);
}
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 49
expectContents(array);
}
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testCreateWithNull_unsupported() {
E[] array = createArrayWithNullElement();
try {
Reported by PMD.
Line: 55
E[] array = createArrayWithNullElement();
try {
getSubjectGenerator().create(array);
fail("Creating a collection containing null should fail");
} catch (NullPointerException expected) {
}
}
Reported by PMD.
Line: 57
try {
getSubjectGenerator().create(array);
fail("Creating a collection containing null should fail");
} catch (NullPointerException expected) {
}
}
/**
* Returns the {@link Method} instance for {@link #testCreateWithNull_unsupported()} so that tests
Reported by PMD.
Line: 57
try {
getSubjectGenerator().create(array);
fail("Creating a collection containing null should fail");
} catch (NullPointerException expected) {
}
}
/**
* Returns the {@link Method} instance for {@link #testCreateWithNull_unsupported()} so that tests
Reported by PMD.
guava-tests/test/com/google/common/eventbus/ReentrantEventsTest.java
6 issues
Line: 33
static final String FIRST = "one";
static final Double SECOND = 2.0d;
final EventBus bus = new EventBus();
public void testNoReentrantEvents() {
ReentrantEventsHater hater = new ReentrantEventsHater();
bus.register(hater);
Reported by PMD.
Line: 35
final EventBus bus = new EventBus();
public void testNoReentrantEvents() {
ReentrantEventsHater hater = new ReentrantEventsHater();
bus.register(hater);
bus.post(FIRST);
Reported by PMD.
Line: 48
}
public class ReentrantEventsHater {
boolean ready = true;
List<Object> eventsReceived = Lists.newArrayList();
@Subscribe
public void listenForStrings(String event) {
eventsReceived.add(event);
Reported by PMD.
Line: 49
public class ReentrantEventsHater {
boolean ready = true;
List<Object> eventsReceived = Lists.newArrayList();
@Subscribe
public void listenForStrings(String event) {
eventsReceived.add(event);
ready = false;
Reported by PMD.
Line: 69
}
}
public void testEventOrderingIsPredictable() {
EventProcessor processor = new EventProcessor();
bus.register(processor);
EventRecorder recorder = new EventRecorder();
bus.register(recorder);
Reported by PMD.
Line: 92
}
public class EventRecorder {
List<Object> eventsReceived = Lists.newArrayList();
@Subscribe
public void listenForEverything(Object event) {
eventsReceived.add(event);
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java
6 issues
Line: 40
public void testEquals_null() {
// noinspection ObjectEqualsNull
assertFalse("An object should not be equal to null.", collection.equals(null));
}
public void testEquals_notACollection() {
// noinspection EqualsBetweenInconvertibleTypes
assertFalse(
Reported by PMD.
Line: 33
public class CollectionEqualsTester<E> extends AbstractCollectionTester<E> {
// TODO(cpovirk): Consider using EqualsTester from Guava.
@SuppressWarnings("SelfEquals")
public void testEquals_self() {
assertTrue("An Object should be equal to itself.", collection.equals(collection));
}
public void testEquals_null() {
Reported by PMD.
Line: 38
assertTrue("An Object should be equal to itself.", collection.equals(collection));
}
public void testEquals_null() {
// noinspection ObjectEqualsNull
assertFalse("An object should not be equal to null.", collection.equals(null));
}
public void testEquals_notACollection() {
Reported by PMD.
Line: 43
assertFalse("An object should not be equal to null.", collection.equals(null));
}
public void testEquals_notACollection() {
// noinspection EqualsBetweenInconvertibleTypes
assertFalse(
"A Collection should never equal an object that is not a Collection.",
collection.equals("huh?"));
}
Reported by PMD.
Line: 47
// noinspection EqualsBetweenInconvertibleTypes
assertFalse(
"A Collection should never equal an object that is not a Collection.",
collection.equals("huh?"));
}
}
Reported by PMD.
Line: 47
// noinspection EqualsBetweenInconvertibleTypes
assertFalse(
"A Collection should never equal an object that is not a Collection.",
collection.equals("huh?"));
}
}
Reported by PMD.
guava-tests/benchmark/com/google/common/base/SplitterBenchmark.java
6 issues
Line: 32
public class SplitterBenchmark {
// overall size of string
@Param({"1", "10", "100", "1000"})
int length;
// Number of matching strings
@Param({"xxxx", "xxXx", "xXxX", "XXXX"})
String text;
private String input;
Reported by PMD.
Line: 35
int length;
// Number of matching strings
@Param({"xxxx", "xxXx", "xXxX", "XXXX"})
String text;
private String input;
private static final Splitter CHAR_SPLITTER = Splitter.on('X');
private static final Splitter STRING_SPLITTER = Splitter.on("X");
Reported by PMD.
Line: 37
@Param({"xxxx", "xxXx", "xXxX", "XXXX"})
String text;
private String input;
private static final Splitter CHAR_SPLITTER = Splitter.on('X');
private static final Splitter STRING_SPLITTER = Splitter.on("X");
@BeforeExperiment
Reported by PMD.
Line: 42
private static final Splitter CHAR_SPLITTER = Splitter.on('X');
private static final Splitter STRING_SPLITTER = Splitter.on("X");
@BeforeExperiment
void setUp() {
input = Strings.repeat(text, length);
}
@Benchmark
Reported by PMD.
Line: 49
@Benchmark
void charSplitter(int reps) {
int total = 0;
for (int i = 0; i < reps; i++) {
total += Iterables.size(CHAR_SPLITTER.split(input));
}
}
Reported by PMD.
Line: 58
@Benchmark
void stringSplitter(int reps) {
int total = 0;
for (int i = 0; i < reps; i++) {
total += Iterables.size(STRING_SPLITTER.split(input));
}
}
Reported by PMD.
guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java
6 issues
Line: 48
*/
@GwtIncompatible
class SameThreadScheduledExecutorService extends AbstractExecutorService
implements ListeningScheduledExecutorService {
private final ListeningExecutorService delegate = newDirectExecutorService();
@Override
public void shutdown() {
Reported by PMD.
Line: 50
class SameThreadScheduledExecutorService extends AbstractExecutorService
implements ListeningScheduledExecutorService {
private final ListeningExecutorService delegate = newDirectExecutorService();
@Override
public void shutdown() {
delegate.shutdown();
}
Reported by PMD.
Line: 74
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
Preconditions.checkNotNull(unit, "unit must not be null!");
return delegate.awaitTermination(timeout, unit);
}
@Override
public <T> ListenableFuture<T> submit(Callable<T> task) {
Reported by PMD.
Line: 100
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
Preconditions.checkNotNull(tasks, "tasks must not be null!");
return delegate.invokeAll(tasks);
}
@Override
public <T> List<Future<T>> invokeAll(
Reported by PMD.
Line: 138
public ListenableScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
Preconditions.checkNotNull(command, "command must not be null");
Preconditions.checkNotNull(unit, "unit must not be null!");
return schedule(java.util.concurrent.Executors.callable(command), delay, unit);
}
@Override
public <V> ListenableScheduledFuture<V> schedule(
final Callable<V> callable, long delay, TimeUnit unit) {
Reported by PMD.
Line: 152
private static class ImmediateScheduledFuture<V> extends SimpleForwardingListenableFuture<V>
implements ListenableScheduledFuture<V> {
private ExecutionException exception;
protected ImmediateScheduledFuture(ListenableFuture<V> future) {
super(future);
}
Reported by PMD.
guava-tests/test/com/google/common/base/StopwatchJavaTimeTest.java
6 issues
Line: 27
/** Unit test for the {@code java.time} support in {@link Stopwatch}. */
@GwtIncompatible
public class StopwatchJavaTimeTest extends TestCase {
private final FakeTicker ticker = new FakeTicker();
private final Stopwatch stopwatch = new Stopwatch(ticker);
public void testElapsed_duration() {
stopwatch.start();
ticker.advance(999999);
Reported by PMD.
Line: 28
@GwtIncompatible
public class StopwatchJavaTimeTest extends TestCase {
private final FakeTicker ticker = new FakeTicker();
private final Stopwatch stopwatch = new Stopwatch(ticker);
public void testElapsed_duration() {
stopwatch.start();
ticker.advance(999999);
assertEquals(Duration.ofNanos(999999), stopwatch.elapsed());
Reported by PMD.
Line: 30
private final FakeTicker ticker = new FakeTicker();
private final Stopwatch stopwatch = new Stopwatch(ticker);
public void testElapsed_duration() {
stopwatch.start();
ticker.advance(999999);
assertEquals(Duration.ofNanos(999999), stopwatch.elapsed());
ticker.advance(1);
assertEquals(Duration.ofMillis(1), stopwatch.elapsed());
Reported by PMD.
Line: 30
private final FakeTicker ticker = new FakeTicker();
private final Stopwatch stopwatch = new Stopwatch(ticker);
public void testElapsed_duration() {
stopwatch.start();
ticker.advance(999999);
assertEquals(Duration.ofNanos(999999), stopwatch.elapsed());
ticker.advance(1);
assertEquals(Duration.ofMillis(1), stopwatch.elapsed());
Reported by PMD.
Line: 33
public void testElapsed_duration() {
stopwatch.start();
ticker.advance(999999);
assertEquals(Duration.ofNanos(999999), stopwatch.elapsed());
ticker.advance(1);
assertEquals(Duration.ofMillis(1), stopwatch.elapsed());
}
}
Reported by PMD.
Line: 35
ticker.advance(999999);
assertEquals(Duration.ofNanos(999999), stopwatch.elapsed());
ticker.advance(1);
assertEquals(Duration.ofMillis(1), stopwatch.elapsed());
}
}
Reported by PMD.
guava-tests/benchmark/com/google/common/collect/HashMultisetAddPresentBenchmark.java
6 issues
Line: 31
public class HashMultisetAddPresentBenchmark {
private static final int ARRAY_MASK = 0x0ffff;
private static final int ARRAY_SIZE = 0x10000;
List<Multiset<Integer>> multisets = new ArrayList<>(0x10000);
int[] queries = new int[ARRAY_SIZE];
@BeforeExperiment
void setUp() {
Random random = new Random();
Reported by PMD.
Line: 32
private static final int ARRAY_MASK = 0x0ffff;
private static final int ARRAY_SIZE = 0x10000;
List<Multiset<Integer>> multisets = new ArrayList<>(0x10000);
int[] queries = new int[ARRAY_SIZE];
@BeforeExperiment
void setUp() {
Random random = new Random();
multisets.clear();
Reported by PMD.
Line: 34
List<Multiset<Integer>> multisets = new ArrayList<>(0x10000);
int[] queries = new int[ARRAY_SIZE];
@BeforeExperiment
void setUp() {
Random random = new Random();
multisets.clear();
for (int i = 0; i < ARRAY_SIZE; i++) {
HashMultiset<Integer> multiset = HashMultiset.<Integer>create();
Reported by PMD.
Line: 42
HashMultiset<Integer> multiset = HashMultiset.<Integer>create();
multisets.add(multiset);
queries[i] = random.nextInt();
multiset.add(queries[i]);
}
}
@Benchmark
int add(int reps) {
Reported by PMD.
Line: 51
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += multisets.get(j).add(queries[j], 4);
}
return tmp;
}
}
Reported by PMD.
Line: 36
@BeforeExperiment
void setUp() {
Random random = new Random();
multisets.clear();
for (int i = 0; i < ARRAY_SIZE; i++) {
HashMultiset<Integer> multiset = HashMultiset.<Integer>create();
multisets.add(multiset);
queries[i] = random.nextInt();
Reported by PMD.
guava-testlib/src/com/google/common/testing/EqualsTester.java
6 issues
Line: 121
private void testItems() {
for (Object item : Iterables.concat(equalityGroups)) {
assertTrue(item + " must not be Object#equals to null", !item.equals(null));
assertTrue(
item + " must not be Object#equals to an arbitrary object of another class",
!item.equals(NotAnInstance.EQUAL_TO_NOTHING));
assertEquals(item + " must be Object#equals to itself", item, item);
assertEquals(
Reported by PMD.
Line: 82
public final class EqualsTester {
private static final int REPETITIONS = 3;
private final List<List<Object>> equalityGroups = Lists.newArrayList();
private final RelationshipTester.ItemReporter itemReporter;
/** Constructs an empty EqualsTester instance */
public EqualsTester() {
this(new RelationshipTester.ItemReporter());
Reported by PMD.
Line: 83
private static final int REPETITIONS = 3;
private final List<List<Object>> equalityGroups = Lists.newArrayList();
private final RelationshipTester.ItemReporter itemReporter;
/** Constructs an empty EqualsTester instance */
public EqualsTester() {
this(new RelationshipTester.ItemReporter());
}
Reported by PMD.
Line: 105
}
/** Run tests on equals method, throwing a failure on an invalid test */
public EqualsTester testEquals() {
RelationshipTester<Object> delegate =
new RelationshipTester<>(
Equivalence.equals(), "Object#equals", "Object#hashCode", itemReporter);
for (List<Object> group : equalityGroups) {
delegate.addRelatedGroup(group);
Reported by PMD.
Line: 119
return this;
}
private void testItems() {
for (Object item : Iterables.concat(equalityGroups)) {
assertTrue(item + " must not be Object#equals to null", !item.equals(null));
assertTrue(
item + " must not be Object#equals to an arbitrary object of another class",
!item.equals(NotAnInstance.EQUAL_TO_NOTHING));
Reported by PMD.
Line: 106
/** Run tests on equals method, throwing a failure on an invalid test */
public EqualsTester testEquals() {
RelationshipTester<Object> delegate =
new RelationshipTester<>(
Equivalence.equals(), "Object#equals", "Object#hashCode", itemReporter);
for (List<Object> group : equalityGroups) {
delegate.addRelatedGroup(group);
}
Reported by PMD.
guava-tests/benchmark/com/google/common/collect/InternersBenchmark.java
6 issues
Line: 48
@Benchmark
int stringIntern(int reps) {
for (int i = 0; i < reps; i++) {
String unused = Double.toHexString(Math.random()).intern();
}
return reps;
}
}
Reported by PMD.
Line: 48
@Benchmark
int stringIntern(int reps) {
for (int i = 0; i < reps; i++) {
String unused = Double.toHexString(Math.random()).intern();
}
return reps;
}
}
Reported by PMD.
Line: 29
public class InternersBenchmark {
@Benchmark
int weakInterner(int reps) {
Interner<String> interner = Interners.newWeakInterner();
for (int i = 0; i < reps; i++) {
interner.intern(Double.toHexString(Math.random()));
}
return reps;
}
Reported by PMD.
Line: 38
@Benchmark
int strongInterner(int reps) {
Interner<String> interner = Interners.newStrongInterner();
for (int i = 0; i < reps; i++) {
interner.intern(Double.toHexString(Math.random()));
}
return reps;
}
Reported by PMD.
Line: 48
@Benchmark
int stringIntern(int reps) {
for (int i = 0; i < reps; i++) {
String unused = Double.toHexString(Math.random()).intern();
}
return reps;
}
}
Reported by PMD.
Line: 48
@Benchmark
int stringIntern(int reps) {
for (int i = 0; i < reps; i++) {
String unused = Double.toHexString(Math.random()).intern();
}
return reps;
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java
6 issues
Line: 38
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAllTester<E> extends AbstractListTester<E> {
@CollectionFeature.Require(SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedAllPresent() {
assertTrue(
"addAll(allPresent) should return true", getList().addAll(MinimalCollection.of(e0())));
expectAdded(e0());
Reported by PMD.
Line: 42
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedAllPresent() {
assertTrue(
"addAll(allPresent) should return true", getList().addAll(MinimalCollection.of(e0())));
expectAdded(e0());
}
@CollectionFeature.Require(absent = SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
Reported by PMD.
Line: 46
expectAdded(e0());
}
@CollectionFeature.Require(absent = SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedAllPresent() {
try {
getList().addAll(MinimalCollection.of(e0()));
fail("addAll(allPresent) should throw");
Reported by PMD.
Line: 50
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedAllPresent() {
try {
getList().addAll(MinimalCollection.of(e0()));
fail("addAll(allPresent) should throw");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
Reported by PMD.
Line: 57
expectUnchanged();
}
@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddAll_withDuplicates() {
MinimalCollection<E> elementsToAdd = MinimalCollection.of(e0(), e1(), e0(), e1());
assertTrue("addAll(hasDuplicates) should return true", getList().addAll(elementsToAdd));
expectAdded(e0(), e1(), e0(), e1());
}
Reported by PMD.
Line: 60
@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddAll_withDuplicates() {
MinimalCollection<E> elementsToAdd = MinimalCollection.of(e0(), e1(), e0(), e1());
assertTrue("addAll(hasDuplicates) should return true", getList().addAll(elementsToAdd));
expectAdded(e0(), e1(), e0(), e1());
}
}
Reported by PMD.