The following issues were found

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

Line: 32

               */
public class MultisetIteratorBenchmark {
  @Param({"0", "1", "16", "256", "4096", "65536"})
  int size;

  LinkedHashMultiset<Object> linkedHashMultiset;
  HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.

            

Reported by PMD.

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

Line: 34

                @Param({"0", "1", "16", "256", "4096", "65536"})
  int size;

  LinkedHashMultiset<Object> linkedHashMultiset;
  HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;


            

Reported by PMD.

Field linkedHashMultiset has the same name as a method
Error

Line: 34

                @Param({"0", "1", "16", "256", "4096", "65536"})
  int size;

  LinkedHashMultiset<Object> linkedHashMultiset;
  HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;


            

Reported by PMD.

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

Line: 35

                int size;

  LinkedHashMultiset<Object> linkedHashMultiset;
  HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;

  @BeforeExperiment

            

Reported by PMD.

Field hashMultiset has the same name as a method
Error

Line: 35

                int size;

  LinkedHashMultiset<Object> linkedHashMultiset;
  HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;

  @BeforeExperiment

            

Reported by PMD.

Field treeMultiset has the same name as a method
Error

Line: 38

                HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;

  @BeforeExperiment
  void setUp() {
    hashMultiset = HashMultiset.create(size);
    linkedHashMultiset = LinkedHashMultiset.create(size);

            

Reported by PMD.

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

Line: 38

                HashMultiset<Object> hashMultiset;

  // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;

  @BeforeExperiment
  void setUp() {
    hashMultiset = HashMultiset.create(size);
    linkedHashMultiset = LinkedHashMultiset.create(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: 40

                // TreeMultiset requires a Comparable element.
  TreeMultiset<Integer> treeMultiset;

  @BeforeExperiment
  void setUp() {
    hashMultiset = HashMultiset.create(size);
    linkedHashMultiset = LinkedHashMultiset.create(size);
    treeMultiset = TreeMultiset.create();


            

Reported by PMD.

The updated value of variable 'i' is never used
Design

Line: 51

                  int sizeRemaining = size;

    // TODO(kevinb): generate better test contents for multisets
    for (int i = 0; sizeRemaining > 0; i++) {
      // The JVM will return interned values for small ints.
      Integer value = random.nextInt(1000) + 128;
      int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
      sizeRemaining -= count;
      hashMultiset.add(value, count);

            

Reported by PMD.

Avoid unused local variables such as 'i'.
Design

Line: 51

                  int sizeRemaining = size;

    // TODO(kevinb): generate better test contents for multisets
    for (int i = 0; sizeRemaining > 0; i++) {
      // The JVM will return interned values for small ints.
      Integer value = random.nextInt(1000) + 128;
      int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
      sizeRemaining -= count;
      hashMultiset.add(value, count);

            

Reported by PMD.

guava-tests/benchmark/com/google/common/collect/IteratorBenchmark.java
13 issues
This class has too many methods, consider refactoring it.
Design

Line: 30

               *
 * @author David Richter
 */
public class IteratorBenchmark {
  @Param({"0", "1", "16", "256", "4096", "65536"})
  int size;

  // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;

            

Reported by PMD.

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

Line: 32

               */
public class IteratorBenchmark {
  @Param({"0", "1", "16", "256", "4096", "65536"})
  int size;

  // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

            

Reported by PMD.

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

Line: 35

                int size;

  // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 36

              
  // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {
    array = new Object[size];

            

Reported by PMD.

Avoid using implementation types like 'ArrayList'; use the interface instead
Design

Line: 36

              
  // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {
    array = new Object[size];

            

Reported by PMD.

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

Line: 37

                // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {
    array = new Object[size];
    arrayList = Lists.newArrayListWithCapacity(size);

            

Reported by PMD.

Avoid using implementation types like 'LinkedList'; use the interface instead
Design

Line: 37

                // use concrete classes to remove any possible polymorphic overhead?
  Object[] array;
  ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {
    array = new Object[size];
    arrayList = Lists.newArrayListWithCapacity(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: 39

                ArrayList<Object> arrayList;
  LinkedList<Object> linkedList;

  @BeforeExperiment
  void setUp() {
    array = new Object[size];
    arrayList = Lists.newArrayListWithCapacity(size);
    linkedList = Lists.newLinkedList();


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 46

                  linkedList = Lists.newLinkedList();

    for (int i = 0; i < size; i++) {
      Object value = new Object();
      array[i] = value;
      arrayList.add(value);
      linkedList.add(value);
    }
  }

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 68

                int arrayIndexedLength(int reps) {
    int sum = 0;
    for (int i = 0; i < reps; i++) {
      for (int index = 0; index < array.length; index++) {
        sum += array[index].hashCode();
      }
    }
    return sum;
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultisetEqualsTester.java
12 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: 34

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetEqualsTester<E> extends AbstractMultisetTester<E> {
  public void testEqualsSameContents() {
    new EqualsTester()
        .addEqualityGroup(
            getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }

            

Reported by PMD.

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

Line: 37

                public void testEqualsSameContents() {
    new EqualsTester()
        .addEqualityGroup(
            getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }

  @CollectionSize.Require(absent = ZERO)
  public void testNotEqualsEmpty() {

            

Reported by PMD.

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

Line: 37

                public void testEqualsSameContents() {
    new EqualsTester()
        .addEqualityGroup(
            getMultiset(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }

  @CollectionSize.Require(absent = ZERO)
  public void testNotEqualsEmpty() {

            

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

                      .testEquals();
  }

  @CollectionSize.Require(absent = ZERO)
  public void testNotEqualsEmpty() {
    new EqualsTester()
        .addEqualityGroup(getMultiset())
        .addEqualityGroup(getSubjectGenerator().create())
        .testEquals();

            

Reported by PMD.

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

Line: 45

                public void testNotEqualsEmpty() {
    new EqualsTester()
        .addEqualityGroup(getMultiset())
        .addEqualityGroup(getSubjectGenerator().create())
        .testEquals();
  }

  public void testHashCodeMatchesEntrySet() {
    assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());

            

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

                      .testEquals();
  }

  public void testHashCodeMatchesEntrySet() {
    assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)

            

Reported by PMD.

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

Line: 50

                }

  public void testHashCodeMatchesEntrySet() {
    assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEqualsMultisetWithNullValue() {

            

Reported by PMD.

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

Line: 50

                }

  public void testHashCodeMatchesEntrySet() {
    assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEqualsMultisetWithNullValue() {

            

Reported by PMD.

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

Line: 50

                }

  public void testHashCodeMatchesEntrySet() {
    assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEqualsMultisetWithNullValue() {

            

Reported by PMD.

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

Line: 53

                  assertEquals(getMultiset().entrySet().hashCode(), getMultiset().hashCode());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEqualsMultisetWithNullValue() {
    new EqualsTester()
        .addEqualityGroup(getMultiset())
        .addEqualityGroup(

            

Reported by PMD.

guava-tests/test/com/google/common/collect/AbstractBiMapTest.java
12 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

              
  // The next two tests verify that map entries are not accessed after they're
  // removed, since IdentityHashMap throws an exception when that occurs.
  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityKeySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");

            

Reported by PMD.

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

Line: 32

                // The next two tests verify that map entries are not accessed after they're
  // removed, since IdentityHashMap throws an exception when that occurs.
  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityKeySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");
    bimap.put(2, "two");

            

Reported by PMD.

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

Line: 39

                  bimap.put(1, "one");
    bimap.put(2, "two");
    bimap.put(3, "three");
    Iterator<Integer> iterator = bimap.keySet().iterator();
    iterator.next();
    iterator.next();
    iterator.remove();
    iterator.next();
    iterator.remove();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 45

                  iterator.remove();
    iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                  iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =

            

Reported by PMD.

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

Line: 46

                  iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =

            

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

                  assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");

            

Reported by PMD.

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

Line: 50

                }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");
    bimap.put(2, "two");

            

Reported by PMD.

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

Line: 57

                  bimap.put(1, "one");
    bimap.put(2, "two");
    bimap.put(3, "three");
    Iterator<Entry<Integer, String>> iterator = bimap.entrySet().iterator();
    iterator.next();
    iterator.next();
    iterator.remove();
    iterator.next();
    iterator.remove();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

                  iterator.remove();
    iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
12 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: 53

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
  public void testIterator() {
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses iterator()
      iteratorElements.add(element);
    }
    Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);

            

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

                  Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testIterationOrdering() {
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses iterator()
      iteratorElements.add(element);
    }

            

Reported by PMD.

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

Line: 71

                  assertEquals("Different ordered iteration", expected, iteratorElements);
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_nullElement() {
    initCollectionWithNullElement();
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses iterator()

            

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

                  Helpers.assertEqualIgnoringOrder(asList(createArrayWithNullElement()), iteratorElements);
  }

  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_removeAffectsBackingCollection() {
    int originalSize = collection.size();
    Iterator<E> iterator = collection.iterator();
    Object element = iterator.next();

            

Reported by PMD.

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

Line: 84

              
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_removeAffectsBackingCollection() {
    int originalSize = collection.size();
    Iterator<E> iterator = collection.iterator();
    Object element = iterator.next();
    // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {

            

Reported by PMD.

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

Line: 91

                  // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {
      Entry<?, ?> entry = (Entry<?, ?>) element;
      element = mapEntry(entry.getKey(), entry.getValue());
    }
    assertTrue(collection.contains(element)); // sanity check
    iterator.remove();
    assertFalse(collection.contains(element));
    assertEquals(originalSize - 1, collection.size());

            

Reported by PMD.

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

Line: 91

                  // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {
      Entry<?, ?> entry = (Entry<?, ?>) element;
      element = mapEntry(entry.getKey(), entry.getValue());
    }
    assertTrue(collection.contains(element)); // sanity check
    iterator.remove();
    assertFalse(collection.contains(element));
    assertEquals(originalSize - 1, collection.size());

            

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

                  assertEquals(originalSize - 1, collection.size());
  }

  @CollectionFeature.Require({KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})
  public void testIterator_knownOrderRemoveSupported() {
    runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)

            

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

                  runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)
  public void testIterator_knownOrderRemoveUnsupported() {
    runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)

            

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

                  runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)
  public void testIterator_unknownOrderRemoveSupported() {
    runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.UNKNOWN_ORDER, getSampleElements());
  }

  @CollectionFeature.Require(absent = {KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})

            

Reported by PMD.

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

Line: 42

                private static final Random random = new Random(42);

  @Param({"10", "1000", "100000", "1000000"})
  private int size;

  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;


            

Reported by PMD.

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

Line: 44

                @Param({"10", "1000", "100000", "1000000"})
  private int size;

  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 46

              
  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    random.nextBytes(testBytes);

            

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

              
  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    random.nextBytes(testBytes);
  }


            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 69

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 79

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes, 1, testBytes.length - 1).asBytes()[0];
    }
    return result;
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'hashFunction' (lines '56'-'62').
Error

Line: 56

              
  @Benchmark
  int hasher(int reps) {
    HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;

            

Reported by PMD.

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

Line: 33

                private static final String EVENT = "Hello";

  /** The executor we use to fake asynchronicity. */
  private FakeExecutor executor;

  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 35

                /** The executor we use to fake asynchronicity. */
  private FakeExecutor executor;

  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    executor = new FakeExecutor();

            

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

              
  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    executor = new FakeExecutor();
    bus = new AsyncEventBus(executor);
  }

            

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

                  bus = new AsyncEventBus(executor);
  }

  public void testBasicDistribution() {
    StringCatcher catcher = new StringCatcher();
    bus.register(catcher);

    // We post the event, but our Executor will not deliver it until instructed.
    bus.post(EVENT);

            

Reported by PMD.

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

Line: 44

                  bus = new AsyncEventBus(executor);
  }

  public void testBasicDistribution() {
    StringCatcher catcher = new StringCatcher();
    bus.register(catcher);

    // We post the event, but our Executor will not deliver it until instructed.
    bus.post(EVENT);

            

Reported by PMD.

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

Line: 52

                  bus.post(EVENT);

    List<String> events = catcher.getEvents();
    assertTrue("No events should be delivered synchronously.", events.isEmpty());

    // Now we find the task in our Executor and explicitly activate it.
    List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());


            

Reported by PMD.

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

Line: 56

              
    // Now we find the task in our Executor and explicitly activate it.
    List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));

            

Reported by PMD.

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

Line: 58

                  List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }


            

Reported by PMD.

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

Line: 58

                  List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }


            

Reported by PMD.

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

Line: 60

              
    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }

  /**
   * An {@link Executor} wanna-be that simply records the tasks it's given. Arguably the Worst

            

Reported by PMD.

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

Line: 44

                private static final int RANDOM_SEED = new Random().nextInt();

  @Param({"10", "1000", "100000", "1000000"})
  private int size;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 46

                @Param({"10", "1000", "100000", "1000000"})
  private int size;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    new Random(RANDOM_SEED).nextBytes(testBytes);

            

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

              
  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    new Random(RANDOM_SEED).nextBytes(testBytes);
  }


            

Reported by PMD.

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

Line: 62

                }

  @Benchmark
  byte crc32Checksum(int reps) throws Exception {
    byte result = 0x01;
    for (int i = 0; i < reps; i++) {
      CRC32 checksum = new CRC32();
      checksum.update(testBytes);
      result = (byte) (result ^ checksum.getValue());

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 65

                byte crc32Checksum(int reps) throws Exception {
    byte result = 0x01;
    for (int i = 0; i < reps; i++) {
      CRC32 checksum = new CRC32();
      checksum.update(testBytes);
      result = (byte) (result ^ checksum.getValue());
    }
    return result;
  }

            

Reported by PMD.

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

Line: 80

                }

  @Benchmark
  byte adler32Checksum(int reps) throws Exception {
    byte result = 0x01;
    for (int i = 0; i < reps; i++) {
      Adler32 checksum = new Adler32();
      checksum.update(testBytes);
      result = (byte) (result ^ checksum.getValue());

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 83

                byte adler32Checksum(int reps) throws Exception {
    byte result = 0x01;
    for (int i = 0; i < reps; i++) {
      Adler32 checksum = new Adler32();
      checksum.update(testBytes);
      result = (byte) (result ^ checksum.getValue());
    }
    return result;
  }

            

Reported by PMD.

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

Line: 95

                private byte runHashFunction(int reps, HashFunction hashFunction) {
    byte result = 0x01;
    // Trick the JVM to prevent it from using the hash function non-polymorphically
    result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
    result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
    }
    return result;

            

Reported by PMD.

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

Line: 95

                private byte runHashFunction(int reps, HashFunction hashFunction) {
    byte result = 0x01;
    // Trick the JVM to prevent it from using the hash function non-polymorphically
    result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
    result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
    }
    return result;

            

Reported by PMD.

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

Line: 96

                  byte result = 0x01;
    // Trick the JVM to prevent it from using the hash function non-polymorphically
    result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
    result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
    }
    return result;
  }

            

Reported by PMD.

guava-tests/benchmark/com/google/common/util/concurrent/MonitorBenchmark.java
12 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

              public class MonitorBenchmark {

  @Param({"10", "100", "1000"})
  int capacity;

  @Param({"Array", "Priority"})
  String queueType;

  @Param boolean useMonitor;

            

Reported by PMD.

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

Line: 36

                int capacity;

  @Param({"Array", "Priority"})
  String queueType;

  @Param boolean useMonitor;

  private BlockingQueue<String> queue;
  private String[] strings;

            

Reported by PMD.

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

Line: 38

                @Param({"Array", "Priority"})
  String queueType;

  @Param boolean useMonitor;

  private BlockingQueue<String> queue;
  private String[] strings;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 40

              
  @Param boolean useMonitor;

  private BlockingQueue<String> queue;
  private String[] strings;

  @BeforeExperiment
  @SuppressWarnings("unchecked")
  void setUp() throws Exception {

            

Reported by PMD.

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

Line: 41

                @Param boolean useMonitor;

  private BlockingQueue<String> queue;
  private String[] strings;

  @BeforeExperiment
  @SuppressWarnings("unchecked")
  void setUp() throws Exception {
    String prefix =

            

Reported by PMD.

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

Line: 43

                private BlockingQueue<String> queue;
  private String[] strings;

  @BeforeExperiment
  @SuppressWarnings("unchecked")
  void setUp() throws Exception {
    String prefix =
        (useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
    String className = prefix + queueType + "BlockingQueue";

            

Reported by PMD.

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

Line: 45

              
  @BeforeExperiment
  @SuppressWarnings("unchecked")
  void setUp() throws Exception {
    String prefix =
        (useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
    String className = prefix + queueType + "BlockingQueue";
    Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
    queue = (BlockingQueue<String>) constructor.newInstance(capacity);

            

Reported by PMD.

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

Line: 49

                  String prefix =
        (useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
    String className = prefix + queueType + "BlockingQueue";
    Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
    queue = (BlockingQueue<String>) constructor.newInstance(capacity);

    strings = new String[capacity];
    for (int i = 0; i < capacity; i++) {
      strings[i] = String.valueOf(Math.random());

            

Reported by PMD.

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

Line: 50

                      (useMonitor ? "com.google.common.util.concurrent.MonitorBased" : "java.util.concurrent.");
    String className = prefix + queueType + "BlockingQueue";
    Constructor<?> constructor = Class.forName(className).getConstructor(int.class);
    queue = (BlockingQueue<String>) constructor.newInstance(capacity);

    strings = new String[capacity];
    for (int i = 0; i < capacity; i++) {
      strings[i] = String.valueOf(Math.random());
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'capacity' (lines '60'-'71').
Error

Line: 60

              
  @Benchmark
  void addsAndRemoves(int reps) {
    int capacity = this.capacity;
    BlockingQueue<String> queue = this.queue;
    String[] strings = this.strings;
    for (int i = 0; i < reps; i++) {
      for (int j = 0; j < capacity; j++) {
        queue.add(strings[j]);

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
12 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: 40

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapGetTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testGet_yes() {
    assertEquals("get(present) should return the associated value", v0(), get(k0()));
  }

  public void testGet_no() {

            

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

                  assertEquals("get(present) should return the associated value", v0(), get(k0()));
  }

  public void testGet_no() {
    assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedButAllowed() {

            

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

                  assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedButAllowed() {
    assertNull("get(null) should return null", get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)

            

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

                  assertNull("get(null) should return null", get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

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

            

Reported by PMD.

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

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

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

            

Reported by PMD.

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

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @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: 62

                  }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testGet_nonNullWhenNullContained() {
    initMapWithNullKey();
    assertNull("get(notPresent) should return null", get(k3()));
  }

            

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

                  assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testGet_nullContained() {
    initMapWithNullKey();
    assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
  }

            

Reported by PMD.

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

Line: 76

                  assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
  }

  public void testGet_wrongType() {
    try {
      assertNull("get(wrongType) should return null or throw", getMap().get(WrongType.VALUE));
    } catch (ClassCastException tolerated) {
    }
  }

            

Reported by PMD.