The following issues were found

guava-tests/test/com/google/common/graph/NetworkMutationTest.java
45 issues
JUnit tests should include assert() or fail()
Design

Line: 40

                private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES

  @Test
  public void directedNetwork() {
    testNetworkMutation(NetworkBuilder.directed());
  }

  @Test
  public void undirectedNetwork() {

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 45

                }

  @Test
  public void undirectedNetwork() {
    testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 49

                  testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 60

                    assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(network.nodes());
      for (int i = 0; i < NUM_EDGES; ++i) {
        // Parallel edges are allowed, so this should always succeed.

            

Reported by PMD.

guava-testlib/src/com/google/common/util/concurrent/testing/AbstractListenableFutureTest.java
45 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

              @GwtIncompatible
public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 44

              public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 46

                protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.
    latch = new CountDownLatch(1);
    future = createListenableFuture(Boolean.TRUE, null, latch);

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 54

                  future = createListenableFuture(Boolean.TRUE, null, latch);
  }

  @Override
  protected void tearDown() throws Exception {

    // Make sure we have no waiting threads.
    latch.countDown();
  }

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 68

                /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];

    // Wait on the future in a separate thread.

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 80

                            @Override
              public void run() {
                try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 82

                              try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }
              }
            })

            

Reported by PMD.

android/guava-testlib/test/com/google/common/testing/FakeTickerTest.java
45 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               * @author Jige Yu
 */
@GwtCompatible(emulated = true)
public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 38

              @GwtCompatible(emulated = true)
public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());
  }


            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 39

              public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 44

                  tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 44

                  tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

              
  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

                public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                  FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                  assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {
    FakeTicker ticker = new FakeTicker();
    assertSame(ticker, ticker.setAutoIncrementStep(10, TimeUnit.NANOSECONDS));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 53

                  assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {
    FakeTicker ticker = new FakeTicker();
    assertSame(ticker, ticker.setAutoIncrementStep(10, TimeUnit.NANOSECONDS));
  }

  public void testAutoIncrementStep_nanos() {

            

Reported by PMD.

guava/src/com/google/common/collect/Iterators.java
45 issues
This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.instanceOf;

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.instanceOf;

            

Reported by PMD.

Possible God Class (WMC=111, ATFD=6, TCC=0.000%)
Design

Line: 72

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Iterators {
  private Iterators() {}

  /**
   * Returns the empty iterator.
   *

            

Reported by PMD.

Avoid really long classes.
Design

Line: 72

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Iterators {
  private Iterators() {}

  /**
   * Returns the empty iterator.
   *

            

Reported by PMD.

The class 'Iterators' has a total cyclomatic complexity of 111 (highest 6).
Design

Line: 72

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Iterators {
  private Iterators() {}

  /**
   * Returns the empty iterator.
   *

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 72

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Iterators {
  private Iterators() {}

  /**
   * Returns the empty iterator.
   *

            

Reported by PMD.

The String literal 'unchecked' appears 7 times in this file; the first occurrence is on line 90
Error

Line: 90

                 * <p>The {@link Iterable} equivalent of this method is {@link ImmutableSet#of()}.
   */
  // Casting to any type is safe since there are no actual elements.
  @SuppressWarnings("unchecked")
  static <T extends @Nullable Object> UnmodifiableListIterator<T> emptyListIterator() {
    return (UnmodifiableListIterator<T>) ArrayItr.EMPTY;
  }

  /**

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 416

                       * one, we can optimistically store the new Iterator and then be willing to throw it out if
         * the user calls remove().)
         */
        return iterator.hasNext() || iterable.iterator().hasNext();
      }

      @Override
      @ParametricNullness
      public T next() {

            

Reported by PMD.

Avoid using redundant field initializer for 'index'
Performance

Line: 468

                private static <I extends Iterator<?>> Iterator<I> consumingForArray(
      final @Nullable I... elements) {
    return new UnmodifiableIterator<I>() {
      int index = 0;

      @Override
      public boolean hasNext() {
        return index < elements.length;
      }

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 642

                        array[count] = iterator.next();
        }
        for (int i = count; i < size; i++) {
          array[i] = null; // for GWT
        }

        List<@Nullable T> list = Collections.unmodifiableList(Arrays.asList(array));
        // TODO(b/192579700): Use a ternary once it no longer confuses our nullness checker.
        if (pad || count == size) {

            

Reported by PMD.

android/guava-testlib/src/com/google/common/util/concurrent/testing/AbstractListenableFutureTest.java
45 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

              @GwtIncompatible
public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 44

              public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 46

                protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.
    latch = new CountDownLatch(1);
    future = createListenableFuture(Boolean.TRUE, null, latch);

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 54

                  future = createListenableFuture(Boolean.TRUE, null, latch);
  }

  @Override
  protected void tearDown() throws Exception {

    // Make sure we have no waiting threads.
    latch.countDown();
  }

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 68

                /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];

    // Wait on the future in a separate thread.

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 80

                            @Override
              public void run() {
                try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 82

                              try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }
              }
            })

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/HashMultisetTest.java
45 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 44

              @GwtCompatible(emulated = true)
public class HashMultisetTest extends TestCase {

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 71

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 71

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

The String literal 'foo' appears 7 times in this file; the first occurrence is on line 73
Error

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 74

                public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 75

                  Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {
    Multiset<String> multiset = HashMultiset.create(50);

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/ListenableFutureTaskTest.java
45 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

               */
public class ListenableFutureTaskTest extends TestCase {

  private ExecutorService exec;

  protected final CountDownLatch runLatch = new CountDownLatch(1);
  protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 38

              
  private ExecutorService exec;

  protected final CountDownLatch runLatch = new CountDownLatch(1);
  protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);

  protected volatile boolean throwException = false;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                private ExecutorService exec;

  protected final CountDownLatch runLatch = new CountDownLatch(1);
  protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);

  protected volatile boolean throwException = false;

  protected final ListenableFutureTask<Integer> task =

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 40

              
  protected final CountDownLatch runLatch = new CountDownLatch(1);
  protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);

  protected volatile boolean throwException = false;

  protected final ListenableFutureTask<Integer> task =
      ListenableFutureTask.create(

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 42

                protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);

  protected volatile boolean throwException = false;

  protected final ListenableFutureTask<Integer> task =
      ListenableFutureTask.create(
          new Callable<Integer>() {
            @Override

            

Reported by PMD.

Avoid using redundant field initializer for 'throwException'
Performance

Line: 42

                protected final CountDownLatch taskLatch = new CountDownLatch(1);
  protected final CountDownLatch listenerLatch = new CountDownLatch(1);

  protected volatile boolean throwException = false;

  protected final ListenableFutureTask<Integer> task =
      ListenableFutureTask.create(
          new Callable<Integer>() {
            @Override

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 44

              
  protected volatile boolean throwException = false;

  protected final ListenableFutureTask<Integer> task =
      ListenableFutureTask.create(
          new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
              runLatch.countDown();

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 58

                          }
          });

  @Override
  protected void setUp() throws Exception {
    super.setUp();

    exec = Executors.newCachedThreadPool();


            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 74

                      directExecutor());
  }

  @Override
  protected void tearDown() throws Exception {
    if (exec != null) {
      exec.shutdown();
    }


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 84

                }


  public void testListenerDoesNotRunUntilTaskCompletes() throws Exception {

    // Test default state of not started.
    assertEquals(1, listenerLatch.getCount());
    assertFalse(task.isDone());
    assertFalse(task.isCancelled());

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapEntriesTester.java
45 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 47

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapEntriesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEntries() {
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapEntriesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEntries() {
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 51

                  assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {
    initMultimapWithNullKey();
    assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 55

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {
    initMultimapWithNullKey();
    assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 58

                  assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 60

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 60

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 63

                  assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {
    initMultimapWithNullValue();
    assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 67

                @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {
    initMultimapWithNullValue();
    assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsEntryWithNullValueAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(k0(), null)));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 70

                  assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsEntryWithNullValueAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(k0(), null)));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
45 issues
Avoid throwing raw exception types.
Design

Line: 319

                  try {
      recurse(0);
    } catch (RuntimeException e) {
      throw new RuntimeException(Arrays.toString(stimuli), e);
    }
  }

  private void recurse(int level) {
    // We're going to reuse the stimuli array 3^steps times by overwriting it

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 44

               * @author Chris Povirk
 */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 45

               */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 46

              @GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 47

              abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 48

                private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 49

                private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 50

                private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.
   */

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 97

                    if (!isPermitted(exception)) {
        String message =
            "Exception "
                + exception.getClass().getSimpleName()
                + " was thrown; expected "
                + getMessage();
        Helpers.fail(exception, message);
      }
    }

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 129

                 * <p>This class is accessible but not supported in GWT as it references {@link
   * PermittedMetaException}.
   */
  protected final class MultiExceptionListIterator implements ListIterator<E> {
    // TODO: track seen elements when order isn't guaranteed
    // TODO: verify contents afterward
    // TODO: something shiny and new instead of Stack
    // TODO: test whether null is supported (create a Feature)
    /**

            

Reported by PMD.

android/guava/src/com/google/common/collect/ImmutableMap.java
45 issues
This class has too many methods, consider refactoring it.
Design

Line: 61

              @GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {

  /**
   * Returns the empty map. This map behaves and performs comparably to {@link
   * Collections#emptyMap}, and is preferable mainly for consistency and maintainability of your
   * code.

            

Reported by PMD.

The String literal 'unchecked' appears 6 times in this file; the first occurrence is on line 70
Error

Line: 70

                 *
   * <p><b>Performance note:</b> the instance returned is a singleton.
   */
  @SuppressWarnings("unchecked")
  public static <K, V> ImmutableMap<K, V> of() {
    return (ImmutableMap<K, V>) RegularImmutableMap.EMPTY;
  }

  /**

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 126

                 *
   * @throws IllegalArgumentException if duplicate keys are provided
   */
  public static <K, V> ImmutableMap<K, V> of(
      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    checkEntryNotNull(k1, v1);
    checkEntryNotNull(k2, v2);
    checkEntryNotNull(k3, v3);
    checkEntryNotNull(k4, v4);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 378

                                (V) requireNonNull(alternatingKeysAndValues[2 * i + 1]));
        }
        Arrays.sort(
            entries, 0, size, Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
        for (int i = 0; i < size; i++) {
          alternatingKeysAndValues[2 * i] = entries[i].getKey();
          alternatingKeysAndValues[2 * i + 1] = entries[i].getValue();
        }
      }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 403

                  if ((map instanceof ImmutableMap) && !(map instanceof SortedMap)) {
      @SuppressWarnings("unchecked") // safe since map is not writable
      ImmutableMap<K, V> kvMap = (ImmutableMap<K, V>) map;
      if (!kvMap.isPartialView()) {
        return kvMap;
      }
    }
    return copyOf(map.entrySet());
  }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 531

              
  @Override
  public boolean containsValue(@CheckForNull Object value) {
    return values().contains(value);
  }

  // Overriding to mark it Nullable
  @Override
  @CheckForNull

            

Reported by PMD.

The method 'getOrDefault(Object, V)' is missing an @Override annotation.
Design

Line: 552

                 */
  // @Override under Java 8 / API Level 24
  @CheckForNull
  public final V getOrDefault(@CheckForNull Object key, @CheckForNull V defaultValue) {
    V result = get(key);
    // TODO(b/192579700): Use a ternary once it no longer confuses our nullness checker.
    if (result != null) {
      return result;
    } else {

            

Reported by PMD.

Field entrySet has the same name as a method
Error

Line: 562

                  }
  }

  @LazyInit @RetainedWith @CheckForNull private transient ImmutableSet<Entry<K, V>> entrySet;

  /**
   * Returns an immutable set of the mappings in this map. The iteration order is specified by the
   * method used to create this map. Typically, this is insertion order.
   */

            

Reported by PMD.

Field keySet has the same name as a method
Error

Line: 576

              
  abstract ImmutableSet<Entry<K, V>> createEntrySet();

  @LazyInit @RetainedWith @CheckForNull private transient ImmutableSet<K> keySet;

  /**
   * Returns an immutable set of the keys in this map, in the same order that they appear in {@link
   * #entrySet}.
   */

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 596

                abstract ImmutableSet<K> createKeySet();

  UnmodifiableIterator<K> keyIterator() {
    final UnmodifiableIterator<Entry<K, V>> entryIterator = entrySet().iterator();
    return new UnmodifiableIterator<K>() {
      @Override
      public boolean hasNext() {
        return entryIterator.hasNext();
      }

            

Reported by PMD.