The following issues were found

android/guava-testlib/src/com/google/common/testing/TearDownStack.java
5 issues
Avoid using implementation types like 'LinkedList'; use the interface instead
Design

Line: 45

                private static final Logger logger = Logger.getLogger(TearDownStack.class.getName());

  @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;

            

Reported by PMD.

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

Line: 45

                private static final Logger logger = Logger.getLogger(TearDownStack.class.getName());

  @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;

            

Reported by PMD.

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

Line: 47

                @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;
  }


            

Reported by PMD.

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

Line: 75

                  for (TearDown tearDown : stackCopy) {
      try {
        tearDown.tearDown();
      } catch (Throwable t) {
        if (suppressThrows) {
          logger.log(Level.INFO, "exception thrown during tearDown", t);
        } else {
          exceptions.add(t);
        }

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 83

                      }
      }
    }
    if (!suppressThrows && (exceptions.size() > 0)) {
      throw ClusterException.create(exceptions);
    }
  }
}

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/StandardMutableDirectedGraphTest.java
5 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 41

                      });
  }

  private final boolean allowsSelfLoops;
  private final ElementOrder<Integer> incidentEdgeOrder;

  public StandardMutableDirectedGraphTest(
      boolean allowsSelfLoops, ElementOrder<Integer> incidentEdgeOrder) {
    this.allowsSelfLoops = allowsSelfLoops;

            

Reported by PMD.

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

Line: 42

                }

  private final boolean allowsSelfLoops;
  private final ElementOrder<Integer> incidentEdgeOrder;

  public StandardMutableDirectedGraphTest(
      boolean allowsSelfLoops, ElementOrder<Integer> incidentEdgeOrder) {
    this.allowsSelfLoops = allowsSelfLoops;
    this.incidentEdgeOrder = incidentEdgeOrder;

            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.directed()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.directed()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.directed()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/collect/SetIterationBenchmark.java
5 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

                  "3", "6", "11", "23", "45", "91", "181", "362", "724", "1448", "2896", "5793", "11585", "23170",
    "46341", "92682", "185364", "370728", "741455", "1482910", "2965821", "5931642"
  })
  private int size;

  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;


            

Reported by PMD.

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

Line: 40

              
  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp

            

Reported by PMD.

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

Line: 43

                private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 46

                private SetImpl impl;

  // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment
  void setUp() {
    CollectionBenchmarkSampleData sampleData =
        new CollectionBenchmarkSampleData(true, random, 0.8, size);

            

Reported by PMD.

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

Line: 48

                // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment
  void setUp() {
    CollectionBenchmarkSampleData sampleData =
        new CollectionBenchmarkSampleData(true, random, 0.8, size);
    setToTest = (Set<Element>) impl.create(sampleData.getValuesInSet());
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/ForwardingQueueTest.java
5 issues
This class has too many methods, consider refactoring it.
Design

Line: 41

               */
public class ForwardingQueueTest extends TestCase {

  static final class StandardImplForwardingQueue<T> extends ForwardingQueue<T> {
    private final Queue<T> backingQueue;

    StandardImplForwardingQueue(Queue<T> backingQueue) {
      this.backingQueue = backingQueue;
    }

            

Reported by PMD.

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

Line: 42

              public class ForwardingQueueTest extends TestCase {

  static final class StandardImplForwardingQueue<T> extends ForwardingQueue<T> {
    private final Queue<T> backingQueue;

    StandardImplForwardingQueue(Queue<T> backingQueue) {
      this.backingQueue = backingQueue;
    }


            

Reported by PMD.

JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 119

                  }
  }

  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTestSuite(ForwardingQueueTest.class);
    suite.addTest(
        QueueTestSuiteBuilder.using(

            

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

                  return suite;
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Queue.class,
            new Function<Queue, Queue>() {

            

Reported by PMD.

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

Line: 143

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Queue.class,
            new Function<Queue, Queue>() {
              @Override

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java
5 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: 31

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListGetTester<E> extends AbstractListTester<E> {
  public void testGet_valid() {
    // This calls get() on each index and checks the result:
    expectContents(createOrderedArray());
  }

  public void testGet_negative() {

            

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

                  expectContents(createOrderedArray());
  }

  public void testGet_negative() {
    try {
      getList().get(-1);
      fail("get(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }

            

Reported by PMD.

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

Line: 38

              
  public void testGet_negative() {
    try {
      getList().get(-1);
      fail("get(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
  }


            

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 testGet_tooLarge() {
    try {
      getList().get(getNumElements());
      fail("get(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }

            

Reported by PMD.

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

Line: 46

              
  public void testGet_tooLarge() {
    try {
      getList().get(getNumElements());
      fail("get(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java
5 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 39

              public class ListIndexOfTester<E> extends AbstractListIndexOfTester<E> {
  @Override
  protected int find(Object o) {
    return getList().indexOf(o);
  }

  @Override
  protected String getMethodName() {
    return "indexOf";

            

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

                  return "indexOf";
  }

  @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);

            

Reported by PMD.

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

Line: 52

                public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }
}

            

Reported by PMD.

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

Line: 54

                  array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '50'-'51').
Error

Line: 50

                @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/StandardMutableUndirectedGraphTest.java
5 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 41

                      });
  }

  private final boolean allowsSelfLoops;
  private final ElementOrder<Integer> incidentEdgeOrder;

  public StandardMutableUndirectedGraphTest(
      boolean allowsSelfLoops, ElementOrder<Integer> incidentEdgeOrder) {
    this.allowsSelfLoops = allowsSelfLoops;

            

Reported by PMD.

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

Line: 42

                }

  private final boolean allowsSelfLoops;
  private final ElementOrder<Integer> incidentEdgeOrder;

  public StandardMutableUndirectedGraphTest(
      boolean allowsSelfLoops, ElementOrder<Integer> incidentEdgeOrder) {
    this.allowsSelfLoops = allowsSelfLoops;
    this.incidentEdgeOrder = incidentEdgeOrder;

            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

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

Line: 52

              
  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .incidentEdgeOrder(incidentEdgeOrder)
        .build();
  }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java
4 issues
Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 49

                 * Creates a new collection containing the given elements; implement this method instead of {@link
   * #create(Object...)}.
   */
  protected abstract List<String> create(String[] elements);

  @Override
  public String[] createArray(int length) {
    return new String[length];
  }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '37'-'40').
Error

Line: 37

              
  @Override
  public List<String> create(Object... elements) {
    String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'i' (lines '38'-'43').
Error

Line: 38

                @Override
  public List<String> create(Object... elements) {
    String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);
  }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '40'-'40').
Error

Line: 40

                  String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);
  }

  /**

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java
4 issues
Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 46

                  return create(array);
  }

  protected abstract Collection<String> create(String[] elements);

  @Override
  public String[] createArray(int length) {
    return new String[length];
  }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '38'-'41').
Error

Line: 38

              
  @Override
  public Collection<String> create(Object... elements) {
    String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'i' (lines '39'-'44').
Error

Line: 39

                @Override
  public Collection<String> create(Object... elements) {
    String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);
  }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '41'-'41').
Error

Line: 41

                  String[] array = new String[elements.length];
    int i = 0;
    for (Object e : elements) {
      array[i++] = (String) e;
    }
    return create(array);
  }

  protected abstract Collection<String> create(String[] elements);

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultisetSerializationTester.java
4 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: 37

              @GwtCompatible // but no-op
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetSerializationTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
  public void testEntrySetSerialization() {
    Set<Multiset.Entry<E>> expected = getMultiset().entrySet();
    assertEquals(expected, SerializableTester.reserialize(expected));
  }


            

Reported by PMD.

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

Line: 39

              public class MultisetSerializationTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
  public void testEntrySetSerialization() {
    Set<Multiset.Entry<E>> expected = getMultiset().entrySet();
    assertEquals(expected, SerializableTester.reserialize(expected));
  }

  @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
  public void testElementSetSerialization() {

            

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

                  assertEquals(expected, SerializableTester.reserialize(expected));
  }

  @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
  public void testElementSetSerialization() {
    Set<E> expected = getMultiset().elementSet();
    assertEquals(expected, SerializableTester.reserialize(expected));
  }
}

            

Reported by PMD.

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

Line: 45

              
  @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
  public void testElementSetSerialization() {
    Set<E> expected = getMultiset().elementSet();
    assertEquals(expected, SerializableTester.reserialize(expected));
  }
}

            

Reported by PMD.