The following issues were found

android/guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java
25 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: 43

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());

            

Reported by PMD.

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

Line: 44

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

            

Reported by PMD.

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

Line: 45

              public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }


            

Reported by PMD.

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

Line: 46

                @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})

            

Reported by PMD.

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

Line: 47

                public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

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

                  assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {
    try {
      Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
      getMap().clear();

            

Reported by PMD.

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

Line: 55

                @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {
    try {
      Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
      getMap().clear();
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success

            

Reported by PMD.

android/guava/src/com/google/common/graph/ForwardingNetwork.java
25 issues
This class has too many methods, consider refactoring it.
Design

Line: 30

               * @author Joshua O'Madadhain
 */
@ElementTypesAreNonnullByDefault
abstract class ForwardingNetwork<N, E> extends AbstractNetwork<N, E> {

  abstract Network<N, E> delegate();

  @Override
  public Set<N> nodes() {

            

Reported by PMD.

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

Line: 36

              
  @Override
  public Set<N> nodes() {
    return delegate().nodes();
  }

  @Override
  public Set<E> edges() {
    return delegate().edges();

            

Reported by PMD.

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

Line: 41

              
  @Override
  public Set<E> edges() {
    return delegate().edges();
  }

  @Override
  public boolean isDirected() {
    return delegate().isDirected();

            

Reported by PMD.

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

Line: 46

              
  @Override
  public boolean isDirected() {
    return delegate().isDirected();
  }

  @Override
  public boolean allowsParallelEdges() {
    return delegate().allowsParallelEdges();

            

Reported by PMD.

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

Line: 51

              
  @Override
  public boolean allowsParallelEdges() {
    return delegate().allowsParallelEdges();
  }

  @Override
  public boolean allowsSelfLoops() {
    return delegate().allowsSelfLoops();

            

Reported by PMD.

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

Line: 56

              
  @Override
  public boolean allowsSelfLoops() {
    return delegate().allowsSelfLoops();
  }

  @Override
  public ElementOrder<N> nodeOrder() {
    return delegate().nodeOrder();

            

Reported by PMD.

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

Line: 61

              
  @Override
  public ElementOrder<N> nodeOrder() {
    return delegate().nodeOrder();
  }

  @Override
  public ElementOrder<E> edgeOrder() {
    return delegate().edgeOrder();

            

Reported by PMD.

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

Line: 66

              
  @Override
  public ElementOrder<E> edgeOrder() {
    return delegate().edgeOrder();
  }

  @Override
  public Set<N> adjacentNodes(N node) {
    return delegate().adjacentNodes(node);

            

Reported by PMD.

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

Line: 71

              
  @Override
  public Set<N> adjacentNodes(N node) {
    return delegate().adjacentNodes(node);
  }

  @Override
  public Set<N> predecessors(N node) {
    return delegate().predecessors(node);

            

Reported by PMD.

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

Line: 76

              
  @Override
  public Set<N> predecessors(N node) {
    return delegate().predecessors(node);
  }

  @Override
  public Set<N> successors(N node) {
    return delegate().successors(node);

            

Reported by PMD.

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ForwardingSortedMultiset.java
25 issues
This class has too many methods, consider refactoring it.
Design

Line: 39

               * @author Louis Wasserman
 */
public abstract class ForwardingSortedMultiset<E> extends ForwardingMultiset<E>
    implements SortedMultiset<E> {
  /** Constructor for use by subclasses. */
  protected ForwardingSortedMultiset() {}

  @Override
  protected abstract SortedMultiset<E> delegate();

            

Reported by PMD.

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

Line: 71

              
  @Override
  public Comparator<? super E> comparator() {
    return delegate().comparator();
  }

  @Override
  public SortedMultiset<E> descendingMultiset() {
    return delegate().descendingMultiset();

            

Reported by PMD.

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

Line: 76

              
  @Override
  public SortedMultiset<E> descendingMultiset() {
    return delegate().descendingMultiset();
  }

  /**
   * A skeleton implementation of a descending multiset view. Normally, {@link
   * #descendingMultiset()} will not reflect any changes you make to the behavior of methods such as

            

Reported by PMD.

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

Line: 101

              
  @Override
  public Entry<E> firstEntry() {
    return delegate().firstEntry();
  }

  /**
   * A sensible definition of {@link #firstEntry()} in terms of {@code entrySet().iterator()}.
   *

            

Reported by PMD.

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

Line: 111

                 * forward to this implementation.
   */
  protected Entry<E> standardFirstEntry() {
    Iterator<Entry<E>> entryIterator = entrySet().iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());

            

Reported by PMD.

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

Line: 116

                    return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());
  }

  @Override
  public Entry<E> lastEntry() {
    return delegate().lastEntry();

            

Reported by PMD.

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

Line: 116

                    return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());
  }

  @Override
  public Entry<E> lastEntry() {
    return delegate().lastEntry();

            

Reported by PMD.

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

Line: 121

              
  @Override
  public Entry<E> lastEntry() {
    return delegate().lastEntry();
  }

  /**
   * A sensible definition of {@link #lastEntry()} in terms of {@code
   * descendingMultiset().entrySet().iterator()}.

            

Reported by PMD.

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

Line: 132

                 * {@link #firstEntry()} to forward to this implementation.
   */
  protected Entry<E> standardLastEntry() {
    Iterator<Entry<E>> entryIterator = descendingMultiset().entrySet().iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());

            

Reported by PMD.

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

Line: 132

                 * {@link #firstEntry()} to forward to this implementation.
   */
  protected Entry<E> standardLastEntry() {
    Iterator<Entry<E>> entryIterator = descendingMultiset().entrySet().iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/AbstractFutureInnocuousThreadTest.java
25 issues
Avoid throwing raw exception types.
Design

Line: 121

                              settableFutureClass.getMethod("create").invoke(null);
                latch.countDown();
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
            });
    // In the failure case, await() will timeout.
    assertTrue(latch.await(2, TimeUnit.SECONDS));
  }

            

Reported by PMD.

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

Line: 34

              /** Tests for {@link AbstractFuture} using an innocuous thread. */

public class AbstractFutureInnocuousThreadTest extends TestCase {
  private ClassLoader oldClassLoader;
  private URLClassLoader classReloader;
  private Class<?> settableFutureClass;
  private SecurityManager oldSecurityManager;

  @Override

            

Reported by PMD.

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

Line: 35

              
public class AbstractFutureInnocuousThreadTest extends TestCase {
  private ClassLoader oldClassLoader;
  private URLClassLoader classReloader;
  private Class<?> settableFutureClass;
  private SecurityManager oldSecurityManager;

  @Override
  protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 36

              public class AbstractFutureInnocuousThreadTest extends TestCase {
  private ClassLoader oldClassLoader;
  private URLClassLoader classReloader;
  private Class<?> settableFutureClass;
  private SecurityManager oldSecurityManager;

  @Override
  protected void setUp() throws Exception {
    // Load the "normal" copy of SettableFuture and related classes.

            

Reported by PMD.

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

Line: 37

                private ClassLoader oldClassLoader;
  private URLClassLoader classReloader;
  private Class<?> settableFutureClass;
  private SecurityManager oldSecurityManager;

  @Override
  protected void setUp() throws Exception {
    // Load the "normal" copy of SettableFuture and related classes.
    SettableFuture<?> unused = SettableFuture.create();

            

Reported by PMD.

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

Line: 39

                private Class<?> settableFutureClass;
  private SecurityManager oldSecurityManager;

  @Override
  protected void setUp() throws Exception {
    // Load the "normal" copy of SettableFuture and related classes.
    SettableFuture<?> unused = SettableFuture.create();
    // Hack to load AbstractFuture et. al. in a new classloader so that it tries to re-read the
    // cancellation-cause system property. This allows us to test what happens if reading the

            

Reported by PMD.

Avoid unused local variables such as 'unused'.
Design

Line: 42

                @Override
  protected void setUp() throws Exception {
    // Load the "normal" copy of SettableFuture and related classes.
    SettableFuture<?> unused = SettableFuture.create();
    // Hack to load AbstractFuture et. al. in a new classloader so that it tries to re-read the
    // cancellation-cause system property. This allows us to test what happens if reading the
    // property is forbidden and then continue running tests normally in one jvm without resorting
    // to even crazier hacks to reset static final boolean fields.
    final String concurrentPackage = SettableFuture.class.getPackage().getName();

            

Reported by PMD.

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

Line: 47

                  // cancellation-cause system property. This allows us to test what happens if reading the
    // property is forbidden and then continue running tests normally in one jvm without resorting
    // to even crazier hacks to reset static final boolean fields.
    final String concurrentPackage = SettableFuture.class.getPackage().getName();
    classReloader =
        new URLClassLoader(ClassPathUtil.getClassPathUrls()) {
          @GuardedBy("loadedClasses")
          final Map<String, Class<?>> loadedClasses = new HashMap<>();


            

Reported by PMD.

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

Line: 47

                  // cancellation-cause system property. This allows us to test what happens if reading the
    // property is forbidden and then continue running tests normally in one jvm without resorting
    // to even crazier hacks to reset static final boolean fields.
    final String concurrentPackage = SettableFuture.class.getPackage().getName();
    classReloader =
        new URLClassLoader(ClassPathUtil.getClassPathUrls()) {
          @GuardedBy("loadedClasses")
          final Map<String, Class<?>> loadedClasses = new HashMap<>();


            

Reported by PMD.

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

Line: 57

                        public Class<?> loadClass(String name) throws ClassNotFoundException {
            if (name.startsWith(concurrentPackage)
                // Use other classloader for ListenableFuture, so that the objects can interact
                && !ListenableFuture.class.getName().equals(name)) {
              synchronized (loadedClasses) {
                Class<?> toReturn = loadedClasses.get(name);
                if (toReturn == null) {
                  toReturn = super.findClass(name);
                  loadedClasses.put(name, toReturn);

            

Reported by PMD.

guava-tests/test/com/google/common/base/FinalizableReferenceQueueTest.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

               */
public class FinalizableReferenceQueueTest extends TestCase {

  private FinalizableReferenceQueue frq;

  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }

            

Reported by PMD.

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

Line: 38

              
  private FinalizableReferenceQueue frq;

  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }



            

Reported by PMD.

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

Line: 40

              
  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

            

Reported by PMD.

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

Line: 44

                }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

    GcFinalization.awaitDone(
        new GcFinalization.FinalizationPredicate() {
          @Override

            

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

                }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

    GcFinalization.awaitDone(
        new GcFinalization.FinalizationPredicate() {
          @Override

            

Reported by PMD.

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

Line: 58

              
  static class MockReference extends FinalizableWeakReference<Object> {

    volatile boolean finalizeReferentCalled;

    MockReference(FinalizableReferenceQueue frq) {
      super(new Object(), frq);
    }


            

Reported by PMD.

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

Line: 74

                 * Keeps a weak reference to the underlying reference queue. When this reference is cleared, we
   * know that the background thread has stopped and released its strong reference.
   */
  private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);

            

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: 77

                private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);
  }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */

            

Reported by PMD.

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

Line: 77

                private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);
  }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */

            

Reported by PMD.

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

Line: 83

                }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */
  FinalizableWeakReference<Object> reference;

  /** Create the FRQ in a method that goes out of scope so that we're sure it will be reclaimed. */
  private void weaklyReferenceQueue() {
    frq = new FinalizableReferenceQueue();
    queueReference = new WeakReference<>(frq.queue);

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java
25 issues
This class has too many methods, consider refactoring it.
Design

Line: 45

              @SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());

            

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: 46

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());
  }

            

Reported by PMD.

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

Line: 49

                @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)

            

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

                  expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  /*
   * absent = ZERO isn't required, since unmodList.add() must
   * throw regardless, but it keeps the method name accurate.
   */

            

Reported by PMD.

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

Line: 61

                 */
  public void testAddAtIndex_unsupportedPresent() {
    try {
      getList().add(0, e0());
      fail("add(n, present) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
  }

            

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: 68

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_supportedNotPresent() {
    getList().add(0, e3());
    expectAdded(0, e3());
  }


            

Reported by PMD.

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

Line: 70

              
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_supportedNotPresent() {
    getList().add(0, e3());
    expectAdded(0, e3());
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)

            

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: 74

                  expectAdded(0, e3());
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().add(0, e3());

            

Reported by PMD.

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

Line: 79

                public void testAddAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().add(0, e3());
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success
    }

            

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: 87

                  }
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_unsupportedNotPresent() {
    try {
      getList().add(0, e3());
      fail("add(n, notPresent) should throw");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/TablesTest.java
25 issues
JUnit tests should include assert() or fail()
Design

Line: 38

              
  // The bulk of the toTable tests can be found in TableCollectorsTest.
  // This gives minimal coverage to the forwarding functions
  public void testToTableSanityTest() {
    Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)

            

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

              
  // The bulk of the toTable tests can be found in TableCollectorsTest.
  // This gives minimal coverage to the forwarding functions
  public void testToTableSanityTest() {
    Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)

            

Reported by PMD.

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

Line: 42

                  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }


            

Reported by PMD.

The String literal 'one' appears 5 times in this file; the first occurrence is on line 42
Error

Line: 42

                  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }


            

Reported by PMD.

The String literal 'uno' appears 5 times in this file; the first occurrence is on line 42
Error

Line: 42

                  Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }


            

Reported by PMD.

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

Line: 43

                      Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }

  public void testToTableMergingSanityTest() {

            

Reported by PMD.

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

Line: 43

                      Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 1);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }

  public void testToTableMergingSanityTest() {

            

Reported by PMD.

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

Line: 48

                      .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }

  public void testToTableMergingSanityTest() {
    Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(
            Cell::getRowKey,
            Cell::getColumnKey,
            Cell::getValue,

            

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: 48

                      .expectCollects(expected, Tables.immutableCell("one", "uno", 1));
  }

  public void testToTableMergingSanityTest() {
    Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector =
        Tables.toTable(
            Cell::getRowKey,
            Cell::getColumnKey,
            Cell::getValue,

            

Reported by PMD.

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

Line: 57

                          Integer::sum,
            HashBasedTable::create);
    HashBasedTable<String, String, Integer> expected = HashBasedTable.create();
    expected.put("one", "uno", 3);
    CollectorTester.of(collector)
        .expectCollects(HashBasedTable.create())
        .expectCollects(
            expected, Tables.immutableCell("one", "uno", 1), Tables.immutableCell("one", "uno", 2));
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapPutIfAbsentTester.java
25 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: 41

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapPutIfAbsentTester<K, V> extends AbstractMapTester<K, V> {

  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutIfAbsent_supportedAbsent() {
    assertNull(
        "putIfAbsent(notPresent, value) should return null", getMap().putIfAbsent(k3(), v3()));
    expectAdded(e3());
  }

            

Reported by PMD.

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

Line: 44

                @MapFeature.Require(SUPPORTS_PUT)
  public void testPutIfAbsent_supportedAbsent() {
    assertNull(
        "putIfAbsent(notPresent, value) should return null", getMap().putIfAbsent(k3(), v3()));
    expectAdded(e3());
  }

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

            

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: 48

                  expectAdded(e3());
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_supportedPresent() {
    assertEquals(
        "putIfAbsent(present, value) should return existing value",
        v0(),

            

Reported by PMD.

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

Line: 54

                  assertEquals(
        "putIfAbsent(present, value) should return existing value",
        v0(),
        getMap().putIfAbsent(k0(), v3()));
    expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  public void testPutIfAbsent_unsupportedAbsent() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  public void testPutIfAbsent_unsupportedAbsent() {
    try {
      getMap().putIfAbsent(k3(), v3());
      fail("putIfAbsent(notPresent, value) should throw");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

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

Line: 61

                @MapFeature.Require(absent = SUPPORTS_PUT)
  public void testPutIfAbsent_unsupportedAbsent() {
    try {
      getMap().putIfAbsent(k3(), v3());
      fail("putIfAbsent(notPresent, value) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
    expectMissing(e3());

            

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: 69

                  expectMissing(e3());
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_unsupportedPresentExistingValue() {
    try {
      assertEquals(
          "putIfAbsent(present, existingValue) should return present or throw",

            

Reported by PMD.

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

Line: 76

                    assertEquals(
          "putIfAbsent(present, existingValue) should return present or throw",
          v0(),
          getMap().putIfAbsent(k0(), v0()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 77

                        "putIfAbsent(present, existingValue) should return present or throw",
          v0(),
          getMap().putIfAbsent(k0(), v0()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)

            

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: 82

                  expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_unsupportedPresentDifferentValue() {
    try {
      getMap().putIfAbsent(k0(), v3());
    } catch (UnsupportedOperationException tolerated) {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java
25 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: 43

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());

            

Reported by PMD.

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

Line: 44

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

            

Reported by PMD.

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

Line: 45

              public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }


            

Reported by PMD.

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

Line: 46

                @MapFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})

            

Reported by PMD.

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

Line: 47

                public void testClear() {
    getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

Reported by PMD.

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

Line: 48

                  getMap().clear();
    assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
    assertEquals(0, getMap().size());
    assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {

            

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

                  assertFalse(getMap().entrySet().iterator().hasNext());
  }

  @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {
    try {
      Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
      getMap().clear();

            

Reported by PMD.

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

Line: 55

                @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithEntrySetIteration() {
    try {
      Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
      getMap().clear();
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success

            

Reported by PMD.

guava-tests/benchmark/com/google/common/base/JoinerBenchmark.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                private static final Joiner JOINER_ON_CHARACTER = Joiner.on(DELIMITER_CHARACTER);

  @Param({"3", "30", "300"})
  int count;

  @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

            

Reported by PMD.

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

Line: 42

                int count;

  @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 44

                @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {
    String component = Strings.repeat("a", componentLength);
    String[] raw = new String[count];

            

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

              
  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {
    String component = Strings.repeat("a", componentLength);
    String[] raw = new String[count];
    Arrays.fill(raw, component);
    components = Arrays.asList(raw);

            

Reported by PMD.

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

Line: 59

                int joinerWithStringDelimiter(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy ^= JOINER_ON_STRING.join(components).length();
    }
    return dummy;
  }

  /** {@link Joiner} with a character delimiter. */

            

Reported by PMD.

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

Line: 69

                int joinerWithCharacterDelimiter(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy ^= JOINER_ON_CHARACTER.join(components).length();
    }
    return dummy;
  }

  /**

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 82

                int joinerInlined(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      StringBuilder sb = new StringBuilder();
      Iterator<String> iterator = components.iterator();
      if (iterator.hasNext()) {
        sb.append(iterator.next().toString());
        while (iterator.hasNext()) {
          sb.append(DELIMITER_STRING);

            

Reported by PMD.

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

Line: 85

                    StringBuilder sb = new StringBuilder();
      Iterator<String> iterator = components.iterator();
      if (iterator.hasNext()) {
        sb.append(iterator.next().toString());
        while (iterator.hasNext()) {
          sb.append(DELIMITER_STRING);
          sb.append(iterator.next());
        }
      }

            

Reported by PMD.

This is an inefficient use of StringBuffer.toString; call StringBuffer.length instead.
Performance

Line: 91

                        sb.append(iterator.next());
        }
      }
      dummy ^= sb.toString().length();
    }
    return dummy;
  }

  /**

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 104

                int stringBuilderIsEmpty(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      StringBuilder sb = new StringBuilder();
      for (String comp : components) {
        if (sb.length() > 0) {
          sb.append(DELIMITER_STRING);
        }
        sb.append(comp);

            

Reported by PMD.