The following issues were found

android/guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java
15 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: 42

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> {
  @SuppressWarnings("unchecked")
  @CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER})
  public void testRemovingIteratorKnownOrder() {
    new IteratorTester<E>(
        4,
        MODIFIABLE,

            

Reported by PMD.

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

Line: 42

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> {
  @SuppressWarnings("unchecked")
  @CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER})
  public void testRemovingIteratorKnownOrder() {
    new IteratorTester<E>(
        4,
        MODIFIABLE,

            

Reported by PMD.

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

Line: 48

                  new IteratorTester<E>(
        4,
        MODIFIABLE,
        getSubjectGenerator().order(Arrays.asList(e0(), e1(), e1(), e2())),
        IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }

            

Reported by PMD.

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

Line: 52

                      IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }
    }.test();
  }

  @SuppressWarnings("unchecked")

            

Reported by PMD.

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

Line: 52

                      IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }
    }.test();
  }

  @SuppressWarnings("unchecked")

            

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

                  }.test();
  }

  @SuppressWarnings("unchecked")
  @CollectionFeature.Require(value = SUPPORTS_ITERATOR_REMOVE, absent = KNOWN_ORDER)
  public void testRemovingIteratorUnknownOrder() {
    new IteratorTester<E>(
        4,
        MODIFIABLE,

            

Reported by PMD.

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

Line: 67

                      IteratorTester.KnownOrder.UNKNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }
    }.test();
  }

  @SuppressWarnings("unchecked")

            

Reported by PMD.

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

Line: 67

                      IteratorTester.KnownOrder.UNKNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }
    }.test();
  }

  @SuppressWarnings("unchecked")

            

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

                  }.test();
  }

  @SuppressWarnings("unchecked")
  @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)
  public void testIteratorKnownOrder() {
    new IteratorTester<E>(
        4,
        UNMODIFIABLE,

            

Reported by PMD.

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

Line: 78

                  new IteratorTester<E>(
        4,
        UNMODIFIABLE,
        getSubjectGenerator().order(Arrays.asList(e0(), e1(), e1(), e2())),
        IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<E> newTargetIterator() {
        return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
      }

            

Reported by PMD.

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

Line: 42

               */
public class MessageDigestAlgorithmBenchmark {
  @Param({"10", "1000", "100000", "1000000"})
  int size;

  @Param Algorithm algorithm;
  @Param HashMethod hashMethod;

  private enum HashMethod {

            

Reported by PMD.

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

Line: 44

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

  @Param Algorithm algorithm;
  @Param HashMethod hashMethod;

  private enum HashMethod {
    MESSAGE_DIGEST_API() {
      @Override

            

Reported by PMD.

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

Line: 45

                int size;

  @Param Algorithm algorithm;
  @Param HashMethod hashMethod;

  private enum HashMethod {
    MESSAGE_DIGEST_API() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {

            

Reported by PMD.

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

Line: 52

                    @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        MessageDigest md = algorithm.getMessageDigest();
        md.update(input);
        return md.digest();
      }
    },
    HASH_FUNCTION_DIRECT() {
      @Override

            

Reported by PMD.

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

Line: 53

                    public byte[] hash(Algorithm algorithm, byte[] input) {
        MessageDigest md = algorithm.getMessageDigest();
        md.update(input);
        return md.digest();
      }
    },
    HASH_FUNCTION_DIRECT() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {

            

Reported by PMD.

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

Line: 59

                  HASH_FUNCTION_DIRECT() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        return algorithm.getHashFunction().hashBytes(input).asBytes();
      }
    },
    HASH_FUNCTION_VIA_HASHER() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {

            

Reported by PMD.

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

Line: 59

                  HASH_FUNCTION_DIRECT() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        return algorithm.getHashFunction().hashBytes(input).asBytes();
      }
    },
    HASH_FUNCTION_VIA_HASHER() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {

            

Reported by PMD.

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

Line: 65

                  HASH_FUNCTION_VIA_HASHER() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        return algorithm.getHashFunction().newHasher().putBytes(input).hash().asBytes();
      }
    };
    ;

    public abstract byte[] hash(Algorithm algorithm, byte[] input);

            

Reported by PMD.

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

Line: 65

                  HASH_FUNCTION_VIA_HASHER() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        return algorithm.getHashFunction().newHasher().putBytes(input).hash().asBytes();
      }
    };
    ;

    public abstract byte[] hash(Algorithm algorithm, byte[] input);

            

Reported by PMD.

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

Line: 65

                  HASH_FUNCTION_VIA_HASHER() {
      @Override
      public byte[] hash(Algorithm algorithm, byte[] input) {
        return algorithm.getHashFunction().newHasher().putBytes(input).hash().asBytes();
      }
    };
    ;

    public abstract byte[] hash(Algorithm algorithm, byte[] input);

            

Reported by PMD.

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

Line: 38

               */
public class SortedCopyBenchmark {
  @Param({"1", "10", "1000", "1000000"})
  int size; // logarithmic triangular

  @Param boolean mutable;

  @Param InputOrder inputOrder;


            

Reported by PMD.

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

Line: 40

                @Param({"1", "10", "1000", "1000000"})
  int size; // logarithmic triangular

  @Param boolean mutable;

  @Param InputOrder inputOrder;

  enum InputOrder {
    SORTED {

            

Reported by PMD.

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

Line: 42

              
  @Param boolean mutable;

  @Param InputOrder inputOrder;

  enum InputOrder {
    SORTED {
      @Override
      void arrange(List<Integer> list) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 55

                    @Override
      void arrange(List<Integer> list) {
        Collections.sort(list);
        if (list.size() > 1) {
          int i = (list.size() - 1) / 2;
          Collections.swap(list, i, i + 1);
        }
      }
    },

            

Reported by PMD.

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

Line: 69

                  abstract void arrange(List<Integer> list);
  }

  private ImmutableList<Integer> input;

  @BeforeExperiment
  void setUp() {
    checkArgument(size > 0, "empty collection not supported");
    Set<Integer> set = new LinkedHashSet<>(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: 71

              
  private ImmutableList<Integer> input;

  @BeforeExperiment
  void setUp() {
    checkArgument(size > 0, "empty collection not supported");
    Set<Integer> set = new LinkedHashSet<>(size);

    Random random = new Random();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 91

                  // Yes, this could be done more elegantly
    if (mutable) {
      for (int i = 0; i < reps; i++) {
        List<Integer> copy = new ArrayList<>(input);
        Collections.sort(copy);
        dummy += copy.get(0);
      }
    } else {
      for (int i = 0; i < reps; i++) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 97

                    }
    } else {
      for (int i = 0; i < reps; i++) {
        List<Integer> copy = new ArrayList<>(input);
        Collections.sort(copy);
        dummy += ImmutableList.copyOf(copy).get(0);
      }
    }
    return dummy;

            

Reported by PMD.

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

Line: 99

                    for (int i = 0; i < reps; i++) {
        List<Integer> copy = new ArrayList<>(input);
        Collections.sort(copy);
        dummy += ImmutableList.copyOf(copy).get(0);
      }
    }
    return dummy;
  }


            

Reported by PMD.

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

Line: 110

                  int dummy = 0;
    if (mutable) {
      for (int i = 0; i < reps; i++) {
        dummy += ORDERING.sortedCopy(input).get(0);
      }
    } else {
      for (int i = 0; i < reps; i++) {
        dummy += ORDERING.immutableSortedCopy(input).get(0);
      }

            

Reported by PMD.

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

Line: 45

              @SuppressWarnings("serial") // No serialization is used in this test
@GwtCompatible(emulated = true)
public class SimpleAbstractMultisetTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SimpleAbstractMultisetTest.class);
    suite.addTest(
        MultisetTestSuiteBuilder.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: 68

                  return suite;
  }

  public void testFastAddAllMultiset() {
    final AtomicInteger addCalls = new AtomicInteger();
    Multiset<String> multiset =
        new NoRemoveMultiset<String>() {
          @Override
          public int add(String element, int occurrences) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 81

                  ImmutableMultiset<String> adds =
        new ImmutableMultiset.Builder<String>().addCopies("x", 10).build();
    multiset.addAll(adds);
    assertEquals(1, addCalls.get());
  }

  public void testRemoveUnsupported() {
    Multiset<String> multiset = new NoRemoveMultiset<>();
    multiset.add("a");

            

Reported by PMD.

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

Line: 84

                  assertEquals(1, addCalls.get());
  }

  public void testRemoveUnsupported() {
    Multiset<String> multiset = new NoRemoveMultiset<>();
    multiset.add("a");
    try {
      multiset.remove("a");
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 89

                  multiset.add("a");
    try {
      multiset.remove("a");
      fail();
    } catch (UnsupportedOperationException expected) {
    }
    assertTrue(multiset.contains("a"));
  }


            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 89

                  multiset.add("a");
    try {
      multiset.remove("a");
      fail();
    } catch (UnsupportedOperationException expected) {
    }
    assertTrue(multiset.contains("a"));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 92

                    fail();
    } catch (UnsupportedOperationException expected) {
    }
    assertTrue(multiset.contains("a"));
  }

  private static class NoRemoveMultiset<E> extends AbstractMultiset<E> implements Serializable {
    final Map<E, Integer> backingMap = Maps.newHashMap();


            

Reported by PMD.

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

Line: 140

              
    @Override
    Iterator<Entry<E>> entryIterator() {
      final Iterator<Map.Entry<E, Integer>> backingEntries = backingMap.entrySet().iterator();
      return new UnmodifiableIterator<Multiset.Entry<E>>() {
        @Override
        public boolean hasNext() {
          return backingEntries.hasNext();
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'multiset' (lines '70'-'82').
Error

Line: 70

              
  public void testFastAddAllMultiset() {
    final AtomicInteger addCalls = new AtomicInteger();
    Multiset<String> multiset =
        new NoRemoveMultiset<String>() {
          @Override
          public int add(String element, int occurrences) {
            addCalls.incrementAndGet();
            return super.add(element, occurrences);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'multiset' (lines '70'-'82').
Error

Line: 70

              
  public void testFastAddAllMultiset() {
    final AtomicInteger addCalls = new AtomicInteger();
    Multiset<String> multiset =
        new NoRemoveMultiset<String>() {
          @Override
          public int add(String element, int occurrences) {
            addCalls.incrementAndGet();
            return super.add(element, occurrences);

            

Reported by PMD.

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

Line: 32

               */
public class BinaryTreeTraverserBenchmark {
  private static class BinaryNode {
    final int x;
    final Optional<BinaryNode> left;
    final Optional<BinaryNode> right;

    BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
      this.x = x;

            

Reported by PMD.

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

Line: 33

              public class BinaryTreeTraverserBenchmark {
  private static class BinaryNode {
    final int x;
    final Optional<BinaryNode> left;
    final Optional<BinaryNode> right;

    BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
      this.x = x;
      this.left = left;

            

Reported by PMD.

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

Line: 34

                private static class BinaryNode {
    final int x;
    final Optional<BinaryNode> left;
    final Optional<BinaryNode> right;

    BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
      this.x = x;
      this.left = left;
      this.right = right;

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 63

                    Optional<BinaryNode> createTree(int size, Random rng) {
        Optional<BinaryNode> root = Optional.absent();
        for (int i = 0; i < size; i++) {
          root = Optional.of(new BinaryNode(rng.nextInt(), root, Optional.<BinaryNode>absent()));
        }
        return root;
      }
    },
    ALL_RIGHT {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 73

                    Optional<BinaryNode> createTree(int size, Random rng) {
        Optional<BinaryNode> root = Optional.absent();
        for (int i = 0; i < size; i++) {
          root = Optional.of(new BinaryNode(rng.nextInt(), Optional.<BinaryNode>absent(), root));
        }
        return root;
      }
    },
    RANDOM {

            

Reported by PMD.

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

Line: 143

                  abstract <T> Iterable<T> view(T root, TreeTraverser<T> viewer);
  }

  private Iterable<BinaryNode> view;

  @Param Topology topology;

  @Param({"1", "100", "10000", "1000000"})
  int size;

            

Reported by PMD.

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

Line: 145

              
  private Iterable<BinaryNode> view;

  @Param Topology topology;

  @Param({"1", "100", "10000", "1000000"})
  int size;

  @Param Traversal traversal;

            

Reported by PMD.

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

Line: 148

                @Param Topology topology;

  @Param({"1", "100", "10000", "1000000"})
  int size;

  @Param Traversal traversal;

  @Param({"1234"})
  SpecialRandom rng;

            

Reported by PMD.

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

Line: 150

                @Param({"1", "100", "10000", "1000000"})
  int size;

  @Param Traversal traversal;

  @Param({"1234"})
  SpecialRandom rng;

  @BeforeExperiment

            

Reported by PMD.

Field traversal has the same name as a method
Error

Line: 150

                @Param({"1", "100", "10000", "1000000"})
  int size;

  @Param Traversal traversal;

  @Param({"1234"})
  SpecialRandom rng;

  @BeforeExperiment

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java
15 issues
Avoid reassigning parameters such as 'mapFeatures'
Design

Line: 198

                }

  public static Set<Feature<?>> computeCommonDerivedCollectionFeatures(
      Set<Feature<?>> mapFeatures) {
    mapFeatures = new HashSet<>(mapFeatures);
    Set<Feature<?>> derivedFeatures = new HashSet<>();
    mapFeatures.remove(CollectionFeature.SERIALIZABLE);
    if (mapFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
      derivedFeatures.add(CollectionFeature.SERIALIZABLE);

            

Reported by PMD.

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

Line: 17

               * limitations under the License.
 */

package com.google.common.collect.testing;

import static com.google.common.collect.testing.DerivedCollectionGenerators.keySetGenerator;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.testing.DerivedCollectionGenerators.MapEntrySetGenerator;

            

Reported by PMD.

High amount of different objects as members denotes a high coupling
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect.testing;

import static com.google.common.collect.testing.DerivedCollectionGenerators.keySetGenerator;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.testing.DerivedCollectionGenerators.MapEntrySetGenerator;

            

Reported by PMD.

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

Line: 97

              
    List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);

    if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
      derivedSuites.add(
          MapTestSuiteBuilder.using(
                  new ReserializedMapGenerator<K, V>(parentBuilder.getSubjectGenerator()))
              .withFeatures(computeReserializedMapFeatures(parentBuilder.getFeatures()))
              .named(parentBuilder.getName() + " reserialized")

            

Reported by PMD.

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

Line: 119

                          .withTearDown(parentBuilder.getTearDown())
            .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())

            

Reported by PMD.

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

Line: 120

                          .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())
            .withTearDown(parentBuilder.getTearDown())

            

Reported by PMD.

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

Line: 120

                          .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())
            .withTearDown(parentBuilder.getTearDown())

            

Reported by PMD.

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

Line: 120

                          .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())
            .withTearDown(parentBuilder.getTearDown())

            

Reported by PMD.

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

Line: 120

                          .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())
            .withTearDown(parentBuilder.getTearDown())

            

Reported by PMD.

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

Line: 120

                          .createTestSuite());

    derivedSuites.add(
        createDerivedKeySetSuite(keySetGenerator(parentBuilder.getSubjectGenerator()))
            .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
            .named(parentBuilder.getName() + " keys")
            .suppressing(parentBuilder.getSuppressedTests())
            .withSetUp(parentBuilder.getSetUp())
            .withTearDown(parentBuilder.getTearDown())

            

Reported by PMD.

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

              public class ListMultimapPutTester<K, V> extends AbstractListMultimapTester<K, V> {
  // MultimapPutTester tests non-duplicate values, but ignores ordering

  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutAddsValueAtEnd() {
    for (K key : sampleKeys()) {
      for (V value : sampleValues()) {
        resetContainer();


            

Reported by PMD.

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

Line: 41

                // MultimapPutTester tests non-duplicate values, but ignores ordering

  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutAddsValueAtEnd() {
    for (K key : sampleKeys()) {
      for (V value : sampleValues()) {
        resetContainer();

        List<V> values = multimap().get(key);

            

Reported by PMD.

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

Line: 46

                    for (V value : sampleValues()) {
        resetContainer();

        List<V> values = multimap().get(key);
        List<V> expectedValues = Helpers.copyToList(values);

        assertTrue(multimap().put(key, value));
        expectedValues.add(value);


            

Reported by PMD.

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

Line: 49

                      List<V> values = multimap().get(key);
        List<V> expectedValues = Helpers.copyToList(values);

        assertTrue(multimap().put(key, value));
        expectedValues.add(value);

        assertGet(key, expectedValues);
        assertEquals(value, values.get(values.size() - 1));
      }

            

Reported by PMD.

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

Line: 50

                      List<V> expectedValues = Helpers.copyToList(values);

        assertTrue(multimap().put(key, value));
        expectedValues.add(value);

        assertGet(key, expectedValues);
        assertEquals(value, values.get(values.size() - 1));
      }
    }

            

Reported by PMD.

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

Line: 53

                      expectedValues.add(value);

        assertGet(key, expectedValues);
        assertEquals(value, values.get(values.size() - 1));
      }
    }
  }

  @MapFeature.Require(SUPPORTS_PUT)

            

Reported by PMD.

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

Line: 53

                      expectedValues.add(value);

        assertGet(key, expectedValues);
        assertEquals(value, values.get(values.size() - 1));
      }
    }
  }

  @MapFeature.Require(SUPPORTS_PUT)

            

Reported by PMD.

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

Line: 58

                  }
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutDuplicateValue() {
    List<Entry<K, V>> entries = copyToList(multimap().entries());

    for (Entry<K, V> entry : entries) {

            

Reported by PMD.

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

Line: 60

              
  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutDuplicateValue() {
    List<Entry<K, V>> entries = copyToList(multimap().entries());

    for (Entry<K, V> entry : entries) {
      resetContainer();


            

Reported by PMD.

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

Line: 61

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutDuplicateValue() {
    List<Entry<K, V>> entries = copyToList(multimap().entries());

    for (Entry<K, V> entry : entries) {
      resetContainer();

      K k = entry.getKey();

            

Reported by PMD.

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

Line: 56

                  }
  }

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MapTestSuiteBuilder.using(new ImmutableEnumMapGenerator())
            .named("Maps.immutableEnumMap")

            

Reported by PMD.

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

Line: 68

                  return suite;
  }

  public void testIteratesOnce() {
    Map<AnEnum, AnEnum> map =
        Maps.asMap(
            ImmutableSet.of(AnEnum.A),
            new Function<AnEnum, AnEnum>() {
              boolean used = false;

            

Reported by PMD.

Avoid using redundant field initializer for 'used'
Performance

Line: 73

                      Maps.asMap(
            ImmutableSet.of(AnEnum.A),
            new Function<AnEnum, AnEnum>() {
              boolean used = false;

              @Override
              public AnEnum apply(AnEnum ae) {
                checkState(!used, "should not be applied more than once");
                used = true;

            

Reported by PMD.

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

Line: 83

                            }
            });
    ImmutableMap<AnEnum, AnEnum> copy = Maps.immutableEnumMap(map);
    assertThat(copy.entrySet()).containsExactly(Helpers.mapEntry(AnEnum.A, AnEnum.A));
  }

  public void testEmptyImmutableEnumMap() {
    ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
    assertEquals(ImmutableMap.of(), map);

            

Reported by PMD.

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

Line: 83

                            }
            });
    ImmutableMap<AnEnum, AnEnum> copy = Maps.immutableEnumMap(map);
    assertThat(copy.entrySet()).containsExactly(Helpers.mapEntry(AnEnum.A, AnEnum.A));
  }

  public void testEmptyImmutableEnumMap() {
    ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
    assertEquals(ImmutableMap.of(), map);

            

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

                  assertThat(copy.entrySet()).containsExactly(Helpers.mapEntry(AnEnum.A, AnEnum.A));
  }

  public void testEmptyImmutableEnumMap() {
    ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
    assertEquals(ImmutableMap.of(), map);
  }

  public void testImmutableEnumMapOrdering() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 88

              
  public void testEmptyImmutableEnumMap() {
    ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
    assertEquals(ImmutableMap.of(), map);
  }

  public void testImmutableEnumMapOrdering() {
    ImmutableMap<AnEnum, String> map =
        Maps.immutableEnumMap(ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));

            

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

                  assertEquals(ImmutableMap.of(), map);
  }

  public void testImmutableEnumMapOrdering() {
    ImmutableMap<AnEnum, String> map =
        Maps.immutableEnumMap(ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));

    assertThat(map.entrySet())
        .containsExactly(

            

Reported by PMD.

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

Line: 95

                  ImmutableMap<AnEnum, String> map =
        Maps.immutableEnumMap(ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));

    assertThat(map.entrySet())
        .containsExactly(
            Helpers.mapEntry(AnEnum.A, "a"),
            Helpers.mapEntry(AnEnum.C, "c"),
            Helpers.mapEntry(AnEnum.E, "e"))
        .inOrder();

            

Reported by PMD.

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

Line: 95

                  ImmutableMap<AnEnum, String> map =
        Maps.immutableEnumMap(ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));

    assertThat(map.entrySet())
        .containsExactly(
            Helpers.mapEntry(AnEnum.A, "a"),
            Helpers.mapEntry(AnEnum.C, "c"),
            Helpers.mapEntry(AnEnum.E, "e"))
        .inOrder();

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/AbstractIdleService.java
15 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class AbstractIdleService implements Service {

  /* Thread names will look like {@code "MyService STARTING"}. */
  private final Supplier<String> threadNameSupplier = new ThreadNameSupplier();

  @WeakOuter

            

Reported by PMD.

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

Line: 39

              public abstract class AbstractIdleService implements Service {

  /* Thread names will look like {@code "MyService STARTING"}. */
  private final Supplier<String> threadNameSupplier = new ThreadNameSupplier();

  @WeakOuter
  private final class ThreadNameSupplier implements Supplier<String> {
    @Override
    public String get() {

            

Reported by PMD.

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

Line: 50

                }

  /* use AbstractService for state management */
  private final Service delegate = new DelegateService();

  @WeakOuter
  private final class DelegateService extends AbstractService {
    @Override
    protected final void doStart() {

            

Reported by PMD.

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

Line: 64

                                try {
                    startUp();
                    notifyStarted();
                  } catch (Throwable t) {
                    notifyFailed(t);
                  }
                }
              });
    }

            

Reported by PMD.

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

Line: 81

                                try {
                    shutDown();
                    notifyStopped();
                  } catch (Throwable t) {
                    notifyFailed(t);
                  }
                }
              });
    }

            

Reported by PMD.

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

Line: 90

              
    @Override
    public String toString() {
      return AbstractIdleService.this.toString();
    }
  }

  /** Constructor for use by subclasses. */
  protected AbstractIdleService() {}

            

Reported by PMD.

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

Line: 90

              
    @Override
    public String toString() {
      return AbstractIdleService.this.toString();
    }
  }

  /** Constructor for use by subclasses. */
  protected AbstractIdleService() {}

            

Reported by PMD.

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

Line: 98

                protected AbstractIdleService() {}

  /** Start the service. */
  protected abstract void startUp() throws Exception;

  /** Stop the service. */
  protected abstract void shutDown() throws Exception;

  /**

            

Reported by PMD.

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

Line: 101

                protected abstract void startUp() throws Exception;

  /** Stop the service. */
  protected abstract void shutDown() throws Exception;

  /**
   * Returns the {@link Executor} that will be used to run this service. Subclasses may override
   * this method to use a custom {@link Executor}, which may configure its worker thread with a
   * specific name, thread group or priority. The returned executor's {@link

            

Reported by PMD.

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

Line: 114

                  return new Executor() {
      @Override
      public void execute(Runnable command) {
        MoreExecutors.newThread(threadNameSupplier.get(), command).start();
      }
    };
  }

  @Override

            

Reported by PMD.

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

Line: 54

              @GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class ForwardingMultiset<E extends @Nullable Object> extends ForwardingCollection<E>
    implements Multiset<E> {

  /** Constructor for use by subclasses. */
  protected ForwardingMultiset() {}

  @Override

            

Reported by PMD.

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

Line: 64

              
  @Override
  public int count(@CheckForNull Object element) {
    return delegate().count(element);
  }

  @CanIgnoreReturnValue
  @Override
  public int add(@ParametricNullness E element, int occurrences) {

            

Reported by PMD.

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

Line: 70

                @CanIgnoreReturnValue
  @Override
  public int add(@ParametricNullness E element, int occurrences) {
    return delegate().add(element, occurrences);
  }

  @CanIgnoreReturnValue
  @Override
  public int remove(@CheckForNull Object element, int occurrences) {

            

Reported by PMD.

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

Line: 76

                @CanIgnoreReturnValue
  @Override
  public int remove(@CheckForNull Object element, int occurrences) {
    return delegate().remove(element, occurrences);
  }

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

            

Reported by PMD.

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

Line: 81

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

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

            

Reported by PMD.

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

Line: 86

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

  @Override
  public boolean equals(@CheckForNull Object object) {
    return object == this || delegate().equals(object);

            

Reported by PMD.

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

Line: 91

              
  @Override
  public boolean equals(@CheckForNull Object object) {
    return object == this || delegate().equals(object);
  }

  @Override
  public int hashCode() {
    return delegate().hashCode();

            

Reported by PMD.

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

Line: 96

              
  @Override
  public int hashCode() {
    return delegate().hashCode();
  }

  @CanIgnoreReturnValue
  @Override
  public int setCount(@ParametricNullness E element, int count) {

            

Reported by PMD.

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

Line: 102

                @CanIgnoreReturnValue
  @Override
  public int setCount(@ParametricNullness E element, int count) {
    return delegate().setCount(element, count);
  }

  @CanIgnoreReturnValue
  @Override
  public boolean setCount(@ParametricNullness E element, int oldCount, int newCount) {

            

Reported by PMD.

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

Line: 108

                @CanIgnoreReturnValue
  @Override
  public boolean setCount(@ParametricNullness E element, int oldCount, int newCount) {
    return delegate().setCount(element, oldCount, newCount);
  }

  /**
   * A sensible definition of {@link #contains} in terms of {@link #count}. If you override {@link
   * #count}, you may wish to override {@link #contains} to forward to this implementation.

            

Reported by PMD.