The following issues were found

guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java
9 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 133

                  }
  }

  private abstract static class TestUnhashableListGenerator
      extends TestUnhashableCollectionGenerator<List<UnhashableObject>>
      implements TestListGenerator<UnhashableObject> {}

  public static class UnhashableElementsImmutableListGenerator extends TestUnhashableListGenerator {
    @Override

            

Reported by PMD.

Class cannot be instantiated and does not provide any static methods or fields
Error

Line: 40

               * @author Hayward Chan
 */
@GwtCompatible
public final class ListGenerators {

  private ListGenerators() {}

  public static class ImmutableListOfGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 65

                public static class BuilderAddAllListGenerator extends TestStringListGenerator {
    @Override
    protected List<String> create(String[] elements) {
      return ImmutableList.<String>builder().addAll(asList(elements)).build();
    }
  }

  public static class BuilderReversedListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 65

                public static class BuilderAddAllListGenerator extends TestStringListGenerator {
    @Override
    protected List<String> create(String[] elements) {
      return ImmutableList.<String>builder().addAll(asList(elements)).build();
    }
  }

  public static class BuilderReversedListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 65

                public static class BuilderAddAllListGenerator extends TestStringListGenerator {
    @Override
    protected List<String> create(String[] elements) {
      return ImmutableList.<String>builder().addAll(asList(elements)).build();
    }
  }

  public static class BuilderReversedListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 74

                  protected List<String> create(String[] elements) {
      List<String> list = asList(elements);
      Collections.reverse(list);
      return ImmutableList.copyOf(list).reverse();
    }
  }

  public static class ImmutableListHeadSubListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 85

                    String[] all = new String[elements.length + suffix.length];
      System.arraycopy(elements, 0, all, 0, elements.length);
      System.arraycopy(suffix, 0, all, elements.length, suffix.length);
      return ImmutableList.copyOf(all).subList(0, elements.length);
    }
  }

  public static class ImmutableListTailSubListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 96

                    String[] all = new String[elements.length + prefix.length];
      System.arraycopy(prefix, 0, all, 0, 2);
      System.arraycopy(elements, 0, all, 2, elements.length);
      return ImmutableList.copyOf(all).subList(2, elements.length + 2);
    }
  }

  public static class ImmutableListMiddleSubListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 111

                    System.arraycopy(elements, 0, all, 2, elements.length);
      System.arraycopy(suffix, 0, all, 2 + elements.length, 2);

      return ImmutableList.copyOf(all).subList(2, elements.length + 2);
    }
  }

  public static class CharactersOfStringGenerator extends TestCharacterListGenerator {
    @Override

            

Reported by PMD.

android/guava/src/com/google/common/collect/MapMaker.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 97

                static final int UNSET_INT = -1;

  // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;

            

Reported by PMD.

Field initialCapacity has the same name as a method
Error

Line: 99

                // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;


            

Reported by PMD.

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

Line: 99

                // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;


            

Reported by PMD.

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

Line: 100

                boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

            

Reported by PMD.

Field concurrencyLevel has the same name as a method
Error

Line: 100

                boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

            

Reported by PMD.

Field keyEquivalence has the same name as a method
Error

Line: 105

                @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

  /**
   * Constructs a new {@code MapMaker} instance with default settings, including strong keys, strong
   * values, and no automatic eviction of any kind.
   */

            

Reported by PMD.

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

Line: 105

                @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

  /**
   * Constructs a new {@code MapMaker} instance with default settings, including strong keys, strong
   * values, and no automatic eviction of any kind.
   */

            

Reported by PMD.

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

Line: 130

                }

  Equivalence<Object> getKeyEquivalence() {
    return MoreObjects.firstNonNull(keyEquivalence, getKeyStrength().defaultEquivalence());
  }

  /**
   * Sets the minimum total size for the internal hash tables. For example, if the initial capacity
   * is {@code 60}, and the concurrency level is {@code 8}, then eight segments are created, each

            

Reported by PMD.

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

Line: 309

                  if (keyEquivalence != null) {
      s.addValue("keyEquivalence");
    }
    return s.toString();
  }
}

            

Reported by PMD.

android/guava-tests/test/com/google/common/io/ByteSinkTester.java
9 issues
Avoid instantiating new objects inside loops
Performance

Line: 69

                    String name, ByteSinkFactory factory, String desc, byte[] bytes) {
    TestSuite suite = new TestSuite(name + " [" + desc + "]");
    for (final Method method : testMethods) {
      suite.addTest(new ByteSinkTester(factory, bytes, name, desc, method));
    }
    return suite;
  }

  private ByteSink sink;

            

Reported by PMD.

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

Line: 74

                  return suite;
  }

  private ByteSink sink;

  ByteSinkTester(
      ByteSinkFactory factory, byte[] data, String suiteName, String caseDesc, Method method) {
    super(factory, data, suiteName, caseDesc, method);
  }

            

Reported by PMD.

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

Line: 81

                  super(factory, data, suiteName, caseDesc, method);
  }

  @Override
  protected void setUp() throws Exception {
    sink = factory.createSink();
  }

  public void testOpenStream() throws IOException {

            

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

                  sink = factory.createSink();
  }

  public void testOpenStream() throws IOException {
    OutputStream out = sink.openStream();
    try {
      ByteStreams.copy(new ByteArrayInputStream(data), out);
    } finally {
      out.close();

            

Reported by PMD.

Consider using a try-with-resources statement instead of explicitly closing the resource
Design

Line: 88

              
  public void testOpenStream() throws IOException {
    OutputStream out = sink.openStream();
    try {
      ByteStreams.copy(new ByteArrayInputStream(data), out);
    } finally {
      out.close();
    }


            

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

                  assertContainsExpectedBytes();
  }

  public void testOpenBufferedStream() throws IOException {
    OutputStream out = sink.openBufferedStream();
    try {
      ByteStreams.copy(new ByteArrayInputStream(data), out);
    } finally {
      out.close();

            

Reported by PMD.

Consider using a try-with-resources statement instead of explicitly closing the resource
Design

Line: 99

              
  public void testOpenBufferedStream() throws IOException {
    OutputStream out = sink.openBufferedStream();
    try {
      ByteStreams.copy(new ByteArrayInputStream(data), out);
    } finally {
      out.close();
    }


            

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

                  assertContainsExpectedBytes();
  }

  public void testWrite() throws IOException {
    sink.write(data);

    assertContainsExpectedBytes();
  }


            

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

                  assertContainsExpectedBytes();
  }

  public void testWriteFrom_inputStream() throws IOException {
    sink.writeFrom(new ByteArrayInputStream(data));

    assertContainsExpectedBytes();
  }


            

Reported by PMD.

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

Line: 45

                      });
  }

  private final boolean allowsSelfLoops;
  private final boolean allowsParallelEdges;
  private final ElementOrder<Integer> nodeOrder;
  private final ElementOrder<String> edgeOrder;

  public StandardMutableUndirectedNetworkTest(

            

Reported by PMD.

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

Line: 46

                }

  private final boolean allowsSelfLoops;
  private final boolean allowsParallelEdges;
  private final ElementOrder<Integer> nodeOrder;
  private final ElementOrder<String> edgeOrder;

  public StandardMutableUndirectedNetworkTest(
      boolean allowsSelfLoops,

            

Reported by PMD.

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

Line: 47

              
  private final boolean allowsSelfLoops;
  private final boolean allowsParallelEdges;
  private final ElementOrder<Integer> nodeOrder;
  private final ElementOrder<String> edgeOrder;

  public StandardMutableUndirectedNetworkTest(
      boolean allowsSelfLoops,
      boolean allowsParallelEdges,

            

Reported by PMD.

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

Line: 48

                private final boolean allowsSelfLoops;
  private final boolean allowsParallelEdges;
  private final ElementOrder<Integer> nodeOrder;
  private final ElementOrder<String> edgeOrder;

  public StandardMutableUndirectedNetworkTest(
      boolean allowsSelfLoops,
      boolean allowsParallelEdges,
      ElementOrder<Integer> nodeOrder,

            

Reported by PMD.

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

Line: 63

              
  @Override
  MutableNetwork<Integer, String> createGraph() {
    return NetworkBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .allowsParallelEdges(allowsParallelEdges)
        .nodeOrder(nodeOrder)
        .edgeOrder(edgeOrder)
        .build();

            

Reported by PMD.

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

Line: 63

              
  @Override
  MutableNetwork<Integer, String> createGraph() {
    return NetworkBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .allowsParallelEdges(allowsParallelEdges)
        .nodeOrder(nodeOrder)
        .edgeOrder(edgeOrder)
        .build();

            

Reported by PMD.

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

Line: 63

              
  @Override
  MutableNetwork<Integer, String> createGraph() {
    return NetworkBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .allowsParallelEdges(allowsParallelEdges)
        .nodeOrder(nodeOrder)
        .edgeOrder(edgeOrder)
        .build();

            

Reported by PMD.

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

Line: 63

              
  @Override
  MutableNetwork<Integer, String> createGraph() {
    return NetworkBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .allowsParallelEdges(allowsParallelEdges)
        .nodeOrder(nodeOrder)
        .edgeOrder(edgeOrder)
        .build();

            

Reported by PMD.

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

Line: 63

              
  @Override
  MutableNetwork<Integer, String> createGraph() {
    return NetworkBuilder.undirected()
        .allowsSelfLoops(allowsSelfLoops)
        .allowsParallelEdges(allowsParallelEdges)
        .nodeOrder(nodeOrder)
        .edgeOrder(edgeOrder)
        .build();

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java
9 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 55

                protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());

    testers.add(CollectionSerializationEqualTester.class);
    testers.add(SetAddAllTester.class);
    testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);

            

Reported by PMD.

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

Line: 56

                  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());

    testers.add(CollectionSerializationEqualTester.class);
    testers.add(SetAddAllTester.class);
    testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);

            

Reported by PMD.

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

Line: 57

              
    testers.add(CollectionSerializationEqualTester.class);
    testers.add(SetAddAllTester.class);
    testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);
    // SetRemoveAllTester doesn't exist because, Sets not permitting

            

Reported by PMD.

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

Line: 58

                  testers.add(CollectionSerializationEqualTester.class);
    testers.add(SetAddAllTester.class);
    testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);
    // SetRemoveAllTester doesn't exist because, Sets not permitting
    // duplicate elements, there are no tests for Set.removeAll() that aren't

            

Reported by PMD.

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

Line: 59

                  testers.add(SetAddAllTester.class);
    testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);
    // SetRemoveAllTester doesn't exist because, Sets not permitting
    // duplicate elements, there are no tests for Set.removeAll() that aren't
    // covered by CollectionRemoveAllTester.

            

Reported by PMD.

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

Line: 60

                  testers.add(SetAddTester.class);
    testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);
    // SetRemoveAllTester doesn't exist because, Sets not permitting
    // duplicate elements, there are no tests for Set.removeAll() that aren't
    // covered by CollectionRemoveAllTester.
    return testers;

            

Reported by PMD.

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

Line: 61

                  testers.add(SetCreationTester.class);
    testers.add(SetHashCodeTester.class);
    testers.add(SetEqualsTester.class);
    testers.add(SetRemoveTester.class);
    // SetRemoveAllTester doesn't exist because, Sets not permitting
    // duplicate elements, there are no tests for Set.removeAll() that aren't
    // covered by CollectionRemoveAllTester.
    return testers;
  }

            

Reported by PMD.

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

Line: 74

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

    if (parentBuilder.getFeatures().contains(SERIALIZABLE)) {
      derivedSuites.add(
          SetTestSuiteBuilder.using(
                  new ReserializedSetGenerator<E>(parentBuilder.getSubjectGenerator()))
              .named(getName() + " reserialized")
              .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))

            

Reported by PMD.

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

Line: 89

                }

  static class ReserializedSetGenerator<E> implements TestSetGenerator<E> {
    final OneSizeTestContainerGenerator<Collection<E>, E> gen;

    private ReserializedSetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
      this.gen = gen;
    }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

               */
@GwtCompatible
public final class OneSizeGenerator<T, E> implements OneSizeTestContainerGenerator<T, E> {
  private final TestContainerGenerator<T, E> generator;
  private final CollectionSize collectionSize;

  public OneSizeGenerator(TestContainerGenerator<T, E> generator, CollectionSize collectionSize) {
    this.generator = generator;
    this.collectionSize = collectionSize;

            

Reported by PMD.

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

Line: 63

              
  @Override
  public T createTestSubject() {
    Collection<E> elements = getSampleElements(getCollectionSize().getNumElements());
    return generator.create(elements.toArray());
  }

  @Override
  public Collection<E> getSampleElements(int howMany) {

            

Reported by PMD.

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

Line: 64

                @Override
  public T createTestSubject() {
    Collection<E> elements = getSampleElements(getCollectionSize().getNumElements());
    return generator.create(elements.toArray());
  }

  @Override
  public Collection<E> getSampleElements(int howMany) {
    SampleElements<E> samples = samples();

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 73

                  @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {
    return collectionSize;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/AbstractTester.java
9 issues
This class name ends with Test but contains no test cases
Error

Line: 34

               * @author George van den Driessche
 */
@GwtCompatible
public class AbstractTester<G> extends TestCase {
  private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;


            

Reported by PMD.

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

Line: 35

               */
@GwtCompatible
public class AbstractTester<G> extends TestCase {
  private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.

            

Reported by PMD.

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

Line: 36

              @GwtCompatible
public class AbstractTester<G> extends TestCase {
  private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override

            

Reported by PMD.

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

Line: 37

              public class AbstractTester<G> extends TestCase {
  private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void setUp() throws Exception {

            

Reported by PMD.

Field setUp has the same name as a method
Error

Line: 37

              public class AbstractTester<G> extends TestCase {
  private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void setUp() throws Exception {

            

Reported by PMD.

Field tearDown has the same name as a method
Error

Line: 38

                private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void setUp() throws Exception {
    if (setUp != null) {

            

Reported by PMD.

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

Line: 38

                private G subjectGenerator;
  private String suiteName;
  private Runnable setUp;
  private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void setUp() throws Exception {
    if (setUp != null) {

            

Reported by PMD.

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

Line: 41

                private Runnable tearDown;

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void setUp() throws Exception {
    if (setUp != null) {
      setUp.run();
    }
  }

            

Reported by PMD.

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

Line: 49

                }

  // public so that it can be referenced in generated GWT tests.
  @Override
  public void tearDown() throws Exception {
    if (tearDown != null) {
      tearDown.run();
    }
  }

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/features/FeatureEnumTest.java
9 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 45

                  assertEquals(
        rootLocaleFormat("%s must have RUNTIME RetentionPolicy.", annotationClass),
        RetentionPolicy.RUNTIME,
        retentionPolicy.value());
    assertNotNull(
        rootLocaleFormat("%s must be inherited.", annotationClass),
        annotationClass.getAnnotation(Inherited.class));

    for (String propertyName : new String[] {"value", "absent"}) {

            

Reported by PMD.

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

Line: 58

                      fail(
            rootLocaleFormat("%s must have a property named '%s'.", annotationClass, propertyName));
      }
      final Class<?> returnType = method.getReturnType();
      assertTrue(
          rootLocaleFormat("%s.%s() must return an array.", annotationClass, propertyName),
          returnType.isArray());
      assertSame(
          rootLocaleFormat(

            

Reported by PMD.

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

Line: 61

                    final Class<?> returnType = method.getReturnType();
      assertTrue(
          rootLocaleFormat("%s.%s() must return an array.", annotationClass, propertyName),
          returnType.isArray());
      assertSame(
          rootLocaleFormat(
              "%s.%s() must return an array of %s.",
              annotationClass, propertyName, annotationClass.getDeclaringClass()),
          annotationClass.getDeclaringClass(),

            

Reported by PMD.

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

Line: 67

                            "%s.%s() must return an array of %s.",
              annotationClass, propertyName, annotationClass.getDeclaringClass()),
          annotationClass.getDeclaringClass(),
          returnType.getComponentType());
    }
  }

  // This is public so that tests for Feature enums we haven't yet imagined
  // can reuse it.

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 77

                    Class<E> featureEnumClass) {
    final Class<?>[] classes = featureEnumClass.getDeclaredClasses();
    for (Class<?> containedClass : classes) {
      if (containedClass.getSimpleName().equals("Require")) {
        if (containedClass.isAnnotation()) {
          assertGoodTesterAnnotation(asAnnotation(containedClass));
        } else {
          fail(
              rootLocaleFormat(

            

Reported by PMD.

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

Line: 77

                    Class<E> featureEnumClass) {
    final Class<?>[] classes = featureEnumClass.getDeclaredClasses();
    for (Class<?> containedClass : classes) {
      if (containedClass.getSimpleName().equals("Require")) {
        if (containedClass.isAnnotation()) {
          assertGoodTesterAnnotation(asAnnotation(containedClass));
        } else {
          fail(
              rootLocaleFormat(

            

Reported by PMD.

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

Line: 105

                  }
  }

  public void testFeatureEnums() throws Exception {
    assertGoodFeatureEnum(CollectionFeature.class);
    assertGoodFeatureEnum(ListFeature.class);
    assertGoodFeatureEnum(SetFeature.class);
    assertGoodFeatureEnum(CollectionSize.class);
    assertGoodFeatureEnum(MapFeature.class);

            

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

                  }
  }

  public void testFeatureEnums() throws Exception {
    assertGoodFeatureEnum(CollectionFeature.class);
    assertGoodFeatureEnum(ListFeature.class);
    assertGoodFeatureEnum(SetFeature.class);
    assertGoodFeatureEnum(CollectionSize.class);
    assertGoodFeatureEnum(MapFeature.class);

            

Reported by PMD.

Found 'DD'-anomaly for variable 'method' (lines '51'-'53').
Error

Line: 51

                      annotationClass.getAnnotation(Inherited.class));

    for (String propertyName : new String[] {"value", "absent"}) {
      Method method = null;
      try {
        method = annotationClass.getMethod(propertyName);
      } catch (NoSuchMethodException e) {
        fail(
            rootLocaleFormat("%s must have a property named '%s'.", annotationClass, propertyName));

            

Reported by PMD.

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

Line: 34

               */
public class LazyStackTraceBenchmark {
  @Param({"20", "200", "2000"})
  int stackDepth;

  @Param({"-1", "3", "15"})
  int breakAt;

  int recursionCount;

            

Reported by PMD.

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

Line: 37

                int stackDepth;

  @Param({"-1", "3", "15"})
  int breakAt;

  int recursionCount;

  private static final Object duh = new Object();


            

Reported by PMD.

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

Line: 39

                @Param({"-1", "3", "15"})
  int breakAt;

  int recursionCount;

  private static final Object duh = new Object();

  @Param Mode mode;


            

Reported by PMD.

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

Line: 43

              
  private static final Object duh = new Object();

  @Param Mode mode;

  enum Mode {
    LAZY_STACK_TRACE {
      @Override
      List<StackTraceElement> getStackTrace(Throwable t) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 63

                    boolean dummy = false;
      for (int i = 0; i < reps; i++) {
        int f = 0;
        Throwable t = new Throwable();
        for (StackTraceElement ste : getStackTrace(t)) {
          dummy |= ste == duh;
          if (f++ == breakAt) {
            break;
          }

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 65

                      int f = 0;
        Throwable t = new Throwable();
        for (StackTraceElement ste : getStackTrace(t)) {
          dummy |= ste == duh;
          if (f++ == breakAt) {
            break;
          }
        }
      }

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 66

                      Throwable t = new Throwable();
        for (StackTraceElement ste : getStackTrace(t)) {
          dummy |= ste == duh;
          if (f++ == breakAt) {
            break;
          }
        }
      }
      return dummy;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'f' (lines '62'-'62').
Error

Line: 62

                  boolean timeIt(int reps, int breakAt) {
      boolean dummy = false;
      for (int i = 0; i < reps; i++) {
        int f = 0;
        Throwable t = new Throwable();
        for (StackTraceElement ste : getStackTrace(t)) {
          dummy |= ste == duh;
          if (f++ == breakAt) {
            break;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'f' (lines '62'-'72').
Error

Line: 62

                  boolean timeIt(int reps, int breakAt) {
      boolean dummy = false;
      for (int i = 0; i < reps; i++) {
        int f = 0;
        Throwable t = new Throwable();
        for (StackTraceElement ste : getStackTrace(t)) {
          dummy |= ste == duh;
          if (f++ == breakAt) {
            break;

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/hash/MessageDigestCreationBenchmark.java
9 issues
getInstance method always creates a new object and hence does not comply to Singleton Design Pattern behaviour. Please review
Error

Line: 42

                }

  @Benchmark
  int getInstance(int reps) throws Exception {
    int retValue = 0;
    for (int i = 0; i < reps; i++) {
      retValue ^= MessageDigest.getInstance(algorithm).getDigestLength();
    }
    return retValue;

            

Reported by PMD.

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

Line: 32

              public class MessageDigestCreationBenchmark {

  @Param({"MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"})
  private String algorithm;

  private MessageDigest md;

  @BeforeExperiment
  void setUp() throws Exception {

            

Reported by PMD.

You shouldnt declare field of MessageDigest type, because unsynchronized access could cause problems
Design

Line: 34

                @Param({"MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"})
  private String algorithm;

  private MessageDigest md;

  @BeforeExperiment
  void setUp() throws Exception {
    md = MessageDigest.getInstance(algorithm);
  }

            

Reported by PMD.

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

Line: 34

                @Param({"MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"})
  private String algorithm;

  private MessageDigest md;

  @BeforeExperiment
  void setUp() throws Exception {
    md = MessageDigest.getInstance(algorithm);
  }

            

Reported by PMD.

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

Line: 36

              
  private MessageDigest md;

  @BeforeExperiment
  void setUp() throws Exception {
    md = MessageDigest.getInstance(algorithm);
  }

  @Benchmark

            

Reported by PMD.

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

Line: 37

                private MessageDigest md;

  @BeforeExperiment
  void setUp() throws Exception {
    md = MessageDigest.getInstance(algorithm);
  }

  @Benchmark
  int getInstance(int reps) throws Exception {

            

Reported by PMD.

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

Line: 42

                }

  @Benchmark
  int getInstance(int reps) throws Exception {
    int retValue = 0;
    for (int i = 0; i < reps; i++) {
      retValue ^= MessageDigest.getInstance(algorithm).getDigestLength();
    }
    return retValue;

            

Reported by PMD.

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

Line: 45

                int getInstance(int reps) throws Exception {
    int retValue = 0;
    for (int i = 0; i < reps; i++) {
      retValue ^= MessageDigest.getInstance(algorithm).getDigestLength();
    }
    return retValue;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 51

                }

  @Benchmark
  int clone(int reps) throws Exception {
    int retValue = 0;
    for (int i = 0; i < reps; i++) {
      retValue ^= ((MessageDigest) md.clone()).getDigestLength();
    }
    return retValue;

            

Reported by PMD.