The following issues were found

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapValuesTester.java
8 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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapValuesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testValues() {
    List<V> expected = Lists.newArrayList();
    for (Entry<K, V> entry : getSampleElements()) {
      expected.add(entry.getValue());
    }
    assertEqualIgnoringOrder(expected, multimap().values());

            

Reported by PMD.

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

Line: 46

                  for (Entry<K, V> entry : getSampleElements()) {
      expected.add(entry.getValue());
    }
    assertEqualIgnoringOrder(expected, multimap().values());
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testValuesInOrder() {
    List<V> expected = Lists.newArrayList();

            

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

                  assertEqualIgnoringOrder(expected, multimap().values());
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testValuesInOrder() {
    List<V> expected = Lists.newArrayList();
    for (Entry<K, V> entry : getOrderedElements()) {
      expected.add(entry.getValue());
    }

            

Reported by PMD.

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

Line: 55

                  for (Entry<K, V> entry : getOrderedElements()) {
      expected.add(entry.getValue());
    }
    assertEqualInOrder(expected, multimap().values());
  }

  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(ONE)
  public void testValuesIteratorRemove() {

            

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

                  assertEqualInOrder(expected, multimap().values());
  }

  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(ONE)
  public void testValuesIteratorRemove() {
    Iterator<V> valuesItr = multimap().values().iterator();
    valuesItr.next();
    valuesItr.remove();

            

Reported by PMD.

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

Line: 61

                @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(ONE)
  public void testValuesIteratorRemove() {
    Iterator<V> valuesItr = multimap().values().iterator();
    valuesItr.next();
    valuesItr.remove();
    assertTrue(multimap().isEmpty());
  }
}

            

Reported by PMD.

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

Line: 61

                @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(ONE)
  public void testValuesIteratorRemove() {
    Iterator<V> valuesItr = multimap().values().iterator();
    valuesItr.next();
    valuesItr.remove();
    assertTrue(multimap().isEmpty());
  }
}

            

Reported by PMD.

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

Line: 64

                  Iterator<V> valuesItr = multimap().values().iterator();
    valuesItr.next();
    valuesItr.remove();
    assertTrue(multimap().isEmpty());
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java
8 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: 36

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class QueueOfferTester<E> extends AbstractQueueTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testOffer_supportedNotPresent() {
    assertTrue("offer(notPresent) should return true", getQueue().offer(e3()));
    expectAdded(e3());
  }


            

Reported by PMD.

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

Line: 38

              public class QueueOfferTester<E> extends AbstractQueueTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testOffer_supportedNotPresent() {
    assertTrue("offer(notPresent) should return true", getQueue().offer(e3()));
    expectAdded(e3());
  }

  @CollectionFeature.Require({SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  public void testOffer_nullSupported() {

            

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

                  expectAdded(e3());
  }

  @CollectionFeature.Require({SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  public void testOffer_nullSupported() {
    assertTrue("offer(null) should return true", getQueue().offer(null));
    expectAdded((E) null);
  }


            

Reported by PMD.

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

Line: 44

              
  @CollectionFeature.Require({SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  public void testOffer_nullSupported() {
    assertTrue("offer(null) should return true", getQueue().offer(null));
    expectAdded((E) null);
  }

  @CollectionFeature.Require(value = SUPPORTS_ADD, absent = ALLOWS_NULL_VALUES)
  public void testOffer_nullUnsupported() {

            

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((E) null);
  }

  @CollectionFeature.Require(value = SUPPORTS_ADD, absent = ALLOWS_NULL_VALUES)
  public void testOffer_nullUnsupported() {
    try {
      getQueue().offer(null);
      fail("offer(null) should throw");
    } catch (NullPointerException expected) {

            

Reported by PMD.

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

Line: 51

                @CollectionFeature.Require(value = SUPPORTS_ADD, absent = ALLOWS_NULL_VALUES)
  public void testOffer_nullUnsupported() {
    try {
      getQueue().offer(null);
      fail("offer(null) should throw");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
    expectNullMissingWhenNullUnsupported("Should not contain null after unsupported offer(null)");

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 53

                  try {
      getQueue().offer(null);
      fail("offer(null) should throw");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
    expectNullMissingWhenNullUnsupported("Should not contain null after unsupported offer(null)");
  }
}

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 53

                  try {
      getQueue().offer(null);
      fail("offer(null) should throw");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
    expectNullMissingWhenNullUnsupported("Should not contain null after unsupported offer(null)");
  }
}

            

Reported by PMD.

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

Line: 44

               * @author Louis Wasserman
 */
public class ForwardingNavigableSetTest extends TestCase {
  static class StandardImplForwardingNavigableSet<T> extends ForwardingNavigableSet<T> {
    private final NavigableSet<T> backingSet;

    StandardImplForwardingNavigableSet(NavigableSet<T> backingSet) {
      this.backingSet = backingSet;
    }

            

Reported by PMD.

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

Line: 45

               */
public class ForwardingNavigableSetTest extends TestCase {
  static class StandardImplForwardingNavigableSet<T> extends ForwardingNavigableSet<T> {
    private final NavigableSet<T> backingSet;

    StandardImplForwardingNavigableSet(NavigableSet<T> backingSet) {
      this.backingSet = backingSet;
    }


            

Reported by PMD.

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

Line: 162

                  }
  }

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

    suite.addTestSuite(ForwardingNavigableSetTest.class);
    suite.addTest(
        SetTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 191

                              new TestStringSetGenerator() {
                  @Override
                  protected Set<String> create(String[] elements) {
                    SafeTreeSet<String> set = new SafeTreeSet<>(Ordering.natural().nullsFirst());
                    Collections.addAll(set, elements);
                    return new StandardImplForwardingNavigableSet<>(set);
                  }

                  @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: 214

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 215

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            NavigableSet.class,
            new Function<NavigableSet, NavigableSet>() {
              @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: 227

                          });
  }

  public void testEquals() {
    NavigableSet<String> set1 = ImmutableSortedSet.of("one");
    NavigableSet<String> set2 = ImmutableSortedSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

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

Line: 227

                          });
  }

  public void testEquals() {
    NavigableSet<String> set1 = ImmutableSortedSet.of("one");
    NavigableSet<String> set2 = ImmutableSortedSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/SafeTreeMapTest.java
8 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 45

               * @author Louis Wasserman
 */
public class SafeTreeMapTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SafeTreeMapTest.class);
    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

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

                  return suite;
  }

  @GwtIncompatible // SerializableTester
  public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(

            

Reported by PMD.

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

Line: 107

                @GwtIncompatible // SerializableTester
  public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

            

Reported by PMD.

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

Line: 108

                public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 109

                  Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester

            

Reported by PMD.

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

Line: 110

                  SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester
  public static class ReserializedMapTests extends SortedMapInterfaceTest<String, Integer> {

            

Reported by PMD.

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

Line: 111

                  SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester
  public static class ReserializedMapTests extends SortedMapInterfaceTest<String, Integer> {
    public ReserializedMapTests() {

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 130

                  }

    @Override
    protected SortedMap<String, Integer> makeEmptyMap() throws UnsupportedOperationException {
      NavigableMap<String, Integer> map = new SafeTreeMap<>();
      return SerializableTester.reserialize(map);
    }

    @Override

            

Reported by PMD.

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

Line: 35

              public class SegmentBenchmark {

  @Param({"16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"})
  int capacity;

  private Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 37

                @Param({"16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"})
  int capacity;

  private Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {
    LocalCache<Object, Object> cache =
        new LocalCache<>(

            

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 Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {
    LocalCache<Object, Object> cache =
        new LocalCache<>(
            CacheBuilder.newBuilder().concurrencyLevel(1).initialCapacity(capacity), null);
    checkState(cache.segments.length == 1);

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 46

                          CacheBuilder.newBuilder().concurrencyLevel(1).initialCapacity(capacity), null);
    checkState(cache.segments.length == 1);
    segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

                  segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

                  segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 50

                  for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")
  @Benchmark
  int time(int reps) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'oldTable' (lines '57'-'66').
Error

Line: 57

                @Benchmark
  int time(int reps) {
    int dummy = 0;
    AtomicReferenceArray<ReferenceEntry<Object, Object>> oldTable = segment.table;
    for (int i = 0; i < reps; i++) {
      // TODO(b/145386688): This access should be guarded by 'this.segment', which is not currently
      // held
      segment.expand();
      segment.table = oldTable;

            

Reported by PMD.

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

Line: 32

               * @author Louis Wasserman
 */
public class ComparatorDelegationOverheadBenchmark {
  private final Integer[][] inputArrays = new Integer[0x100][];

  @Param({"10000"})
  int n;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 35

                private final Integer[][] inputArrays = new Integer[0x100][];

  @Param({"10000"})
  int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {

            

Reported by PMD.

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

Line: 37

                @Param({"10000"})
  int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 38

                int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 41

                void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'rng' (lines '39'-'47').
Error

Line: 39

              
  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }

            

Reported by PMD.

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

Line: 41

                void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }

            

Reported by PMD.

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

Line: 43

                  for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }
  }


            

Reported by PMD.

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

Line: 60

                  "HashBiMapImpl",
    "ImmutableBiMapImpl"
  })
  String implName;

  MapsImplEnum mapsImpl;

  /**
   * A map of contents pre-created before experiment starts to only measure map creation cost. The

            

Reported by PMD.

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

Line: 62

                })
  String implName;

  MapsImplEnum mapsImpl;

  /**
   * A map of contents pre-created before experiment starts to only measure map creation cost. The
   * implementation for the creation of contents is independent and could be different from that of
   * the map under test.

            

Reported by PMD.

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

Line: 69

                 * implementation for the creation of contents is independent and could be different from that of
   * the map under test.
   */
  Map<Element, Element> contents;

  /** Map pre-created before experiment starts to only measure iteration cost during experiment. */
  Map<Element, Element> map;

  CollectionBenchmarkSampleData elems;

            

Reported by PMD.

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

Line: 72

                Map<Element, Element> contents;

  /** Map pre-created before experiment starts to only measure iteration cost during experiment. */
  Map<Element, Element> map;

  CollectionBenchmarkSampleData elems;

  @Param({"0", "1", "100", "10000"})
  int elements;

            

Reported by PMD.

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

Line: 74

                /** Map pre-created before experiment starts to only measure iteration cost during experiment. */
  Map<Element, Element> map;

  CollectionBenchmarkSampleData elems;

  @Param({"0", "1", "100", "10000"})
  int elements;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 77

                CollectionBenchmarkSampleData elems;

  @Param({"0", "1", "100", "10000"})
  int elements;

  @BeforeExperiment
  public void prepareContents() throws Exception {
    mapsImpl = mapEnums.get(implName);
    elems = new CollectionBenchmarkSampleData(elements);

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 80

                int elements;

  @BeforeExperiment
  public void prepareContents() throws Exception {
    mapsImpl = mapEnums.get(implName);
    elems = new CollectionBenchmarkSampleData(elements);
    contents = Maps.newHashMap();
    for (Element key : elems.getValuesInSet()) {
      contents.put(key, key);

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 92

              
  @Benchmark
  @Footprint(exclude = Element.class)
  public Map<Element, Element> create() throws Exception {
    return mapsImpl.create(contents);
  }

  @Benchmark
  public int iterate() {

            

Reported by PMD.

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    collection.clear();
    assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
    assertEquals(0, collection.size());
    assertFalse(collection.iterator().hasNext());

            

Reported by PMD.

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

Line: 42

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testClear() {
    collection.clear();
    assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
    assertEquals(0, collection.size());
    assertFalse(collection.iterator().hasNext());
  }

            

Reported by PMD.

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

Line: 46

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

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testClear_unsupported() {

            

Reported by PMD.

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

Line: 49

                  assertFalse(collection.iterator().hasNext());
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testClear_unsupported() {
    try {
      collection.clear();
      fail(

            

Reported by PMD.

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

Line: 62

                  expectUnchanged();
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  @CollectionSize.Require(ZERO)
  public void testClear_unsupportedByEmptyCollection() {
    try {
      collection.clear();
    } catch (UnsupportedOperationException tolerated) {

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 67

                public void testClear_unsupportedByEmptyCollection() {
    try {
      collection.clear();
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})

            

Reported by PMD.

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

Line: 72

                  expectUnchanged();
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  @CollectionSize.Require(SEVERAL)
  public void testClearConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      collection.clear();

            

Reported by PMD.

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

Line: 42

               * @author Louis Wasserman
 */
public class ForwardingSetTest extends TestCase {
  static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
    private final Set<T> backingSet;

    StandardImplForwardingSet(Set<T> backingSet) {
      this.backingSet = backingSet;
    }

            

Reported by PMD.

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

Line: 43

               */
public class ForwardingSetTest extends TestCase {
  static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
    private final Set<T> backingSet;

    StandardImplForwardingSet(Set<T> backingSet) {
      this.backingSet = backingSet;
    }


            

Reported by PMD.

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

Line: 115

                  }
  }

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

    suite.addTestSuite(ForwardingSetTest.class);
    suite.addTest(
        SetTestSuiteBuilder.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: 148

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 149

                }

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

            

Reported by PMD.

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

Line: 161

                          });
  }

  public void testEquals() {
    Set<String> set1 = ImmutableSet.of("one");
    Set<String> set2 = ImmutableSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

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

                          });
  }

  public void testEquals() {
    Set<String> set1 = ImmutableSet.of("one");
    Set<String> set2 = ImmutableSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java
7 issues
Field factorial has the same name as a method
Error

Line: 36

               */
public class IntMathBenchmark {
  private static int[] exponent = new int[ARRAY_SIZE];
  private static int[] factorial = new int[ARRAY_SIZE];
  private static int[] binomial = new int[ARRAY_SIZE];
  private static final int[] positive = new int[ARRAY_SIZE];
  private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];


            

Reported by PMD.

Field binomial has the same name as a method
Error

Line: 37

              public class IntMathBenchmark {
  private static int[] exponent = new int[ARRAY_SIZE];
  private static int[] factorial = new int[ARRAY_SIZE];
  private static int[] binomial = new int[ARRAY_SIZE];
  private static final int[] positive = new int[ARRAY_SIZE];
  private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];

  @BeforeExperiment

            

Reported by PMD.

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

Line: 42

                private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      exponent[i] = randomExponent();
      factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);

            

Reported by PMD.

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

Line: 48

                    exponent[i] = randomExponent();
      factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
      positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
      nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
      ints[i] = RANDOM_SOURCE.nextInt();
    }
  }


            

Reported by PMD.

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

Line: 49

                    factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
      positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
      nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
      ints[i] = RANDOM_SOURCE.nextInt();
    }
  }

  @Benchmark

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '106'-'110').
Error

Line: 106

              
  @Benchmark
  int isPrime(int reps) {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (IntMath.isPrime(positive[j])) {
        tmp++;
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '110'-'110').
Error

Line: 110

                  for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (IntMath.isPrime(positive[j])) {
        tmp++;
      }
    }
    return tmp;
  }
}

            

Reported by PMD.