The following issues were found

android/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.

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.

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.

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.

android/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java
13 issues
Avoid throwing raw exception types.
Design

Line: 65

                void longEqualJava(int reps) {
    for (int i = 0; i < reps; ++i) {
      if (javaImpl.compare(ba1, ba2) != 0) {
        throw new Error(); // deoptimization
      }
    }
  }

  @Benchmark

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 74

                void longEqualUnsafe(int reps) {
    for (int i = 0; i < reps; ++i) {
      if (unsafeImpl.compare(ba1, ba2) != 0) {
        throw new Error(); // deoptimization
      }
    }
  }

  @Benchmark

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 83

                void diffLastJava(int reps) {
    for (int i = 0; i < reps; ++i) {
      if (javaImpl.compare(ba3, ba4) == 0) {
        throw new Error(); // deoptimization
      }
    }
  }

  @Benchmark

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 92

                void diffLastUnsafe(int reps) {
    for (int i = 0; i < reps; ++i) {
      if (unsafeImpl.compare(ba3, ba4) == 0) {
        throw new Error(); // deoptimization
      }
    }
  }

  /*

            

Reported by PMD.

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

Line: 33

               */
public class UnsignedBytesBenchmark {

  private byte[] ba1;
  private byte[] ba2;
  private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;

            

Reported by PMD.

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

Line: 34

              public class UnsignedBytesBenchmark {

  private byte[] ba1;
  private byte[] ba2;
  private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;


            

Reported by PMD.

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

Line: 35

              
  private byte[] ba1;
  private byte[] ba2;
  private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;

  // 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned)

            

Reported by PMD.

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

Line: 36

                private byte[] ba1;
  private byte[] ba2;
  private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;

  // 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned)
  // @Param({"4", "8", "64", "1024", "1048576", "1048577", "6710884", "6710883"})

            

Reported by PMD.

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

Line: 37

                private byte[] ba2;
  private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;

  // 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned)
  // @Param({"4", "8", "64", "1024", "1048576", "1048577", "6710884", "6710883"})
  @Param({"4", "8", "64", "1024"})

            

Reported by PMD.

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

Line: 38

                private byte[] ba3;
  private byte[] ba4;
  private Comparator<byte[]> javaImpl;
  private Comparator<byte[]> unsafeImpl;

  // 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned)
  // @Param({"4", "8", "64", "1024", "1048576", "1048577", "6710884", "6710883"})
  @Param({"4", "8", "64", "1024"})
  private int length;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java
13 issues
Logger calls should be surrounded by log level guards.
Design

Line: 64

                  Set<Feature<?>> features = Helpers.copyToSet(getFeatures());
    List<Class<? extends AbstractTester>> testers = getTesters();

    logger.fine(" Testing: " + name);

    // Split out all the specified sizes.
    Set<Feature<?>> sizesToTest = Helpers.<Feature<?>>copyToSet(CollectionSize.values());
    sizesToTest.retainAll(features);
    features.removeAll(sizesToTest);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 75

                  sizesToTest.retainAll(
        Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));

    logger.fine("   Sizes: " + formatFeatureSet(sizesToTest));

    if (sizesToTest.isEmpty()) {
      throw new IllegalStateException(
          name
              + ": no CollectionSizes specified (check the argument to "

            

Reported by PMD.

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

Line: 68

              
    // Split out all the specified sizes.
    Set<Feature<?>> sizesToTest = Helpers.<Feature<?>>copyToSet(CollectionSize.values());
    sizesToTest.retainAll(features);
    features.removeAll(sizesToTest);

    FeatureUtil.addImpliedFeatures(sizesToTest);
    sizesToTest.retainAll(
        Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));

            

Reported by PMD.

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

Line: 69

                  // Split out all the specified sizes.
    Set<Feature<?>> sizesToTest = Helpers.<Feature<?>>copyToSet(CollectionSize.values());
    sizesToTest.retainAll(features);
    features.removeAll(sizesToTest);

    FeatureUtil.addImpliedFeatures(sizesToTest);
    sizesToTest.retainAll(
        Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));


            

Reported by PMD.

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

Line: 72

                  features.removeAll(sizesToTest);

    FeatureUtil.addImpliedFeatures(sizesToTest);
    sizesToTest.retainAll(
        Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));

    logger.fine("   Sizes: " + formatFeatureSet(sizesToTest));

    if (sizesToTest.isEmpty()) {

            

Reported by PMD.

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

Line: 77

              
    logger.fine("   Sizes: " + formatFeatureSet(sizesToTest));

    if (sizesToTest.isEmpty()) {
      throw new IllegalStateException(
          name
              + ": no CollectionSizes specified (check the argument to "
              + "FeatureSpecificTestSuiteBuilder.withFeatures().)");
    }

            

Reported by PMD.

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

Line: 88

                  for (Feature<?> collectionSize : sizesToTest) {
      String oneSizeName =
          Platform.format(
              "%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
      OneSizeGenerator<T, E> oneSizeGenerator =
          new OneSizeGenerator<>(getSubjectGenerator(), (CollectionSize) collectionSize);
      Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
      oneSizeFeatures.add(collectionSize);
      Set<Method> oneSizeSuppressedTests = getSuppressedTests();

            

Reported by PMD.

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Error

Line: 88

                  for (Feature<?> collectionSize : sizesToTest) {
      String oneSizeName =
          Platform.format(
              "%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
      OneSizeGenerator<T, E> oneSizeGenerator =
          new OneSizeGenerator<>(getSubjectGenerator(), (CollectionSize) collectionSize);
      Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
      oneSizeFeatures.add(collectionSize);
      Set<Method> oneSizeSuppressedTests = getSuppressedTests();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 90

                        Platform.format(
              "%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
      OneSizeGenerator<T, E> oneSizeGenerator =
          new OneSizeGenerator<>(getSubjectGenerator(), (CollectionSize) collectionSize);
      Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
      oneSizeFeatures.add(collectionSize);
      Set<Method> oneSizeSuppressedTests = getSuppressedTests();

      OneSizeTestSuiteBuilder<T, E> oneSizeBuilder =

            

Reported by PMD.

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

Line: 92

                    OneSizeGenerator<T, E> oneSizeGenerator =
          new OneSizeGenerator<>(getSubjectGenerator(), (CollectionSize) collectionSize);
      Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
      oneSizeFeatures.add(collectionSize);
      Set<Method> oneSizeSuppressedTests = getSuppressedTests();

      OneSizeTestSuiteBuilder<T, E> oneSizeBuilder =
          new OneSizeTestSuiteBuilder<T, E>(testers)
              .named(oneSizeName)

            

Reported by PMD.

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

Line: 33

              
  /** Helper class for testing behavior with Flushable and Closeable targets. */
  private static class SpyAppendable implements Appendable, Flushable, Closeable {
    boolean flushed;
    boolean closed;
    StringBuilder result = new StringBuilder();

    @Override
    public Appendable append(CharSequence csq) {

            

Reported by PMD.

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

Line: 34

                /** Helper class for testing behavior with Flushable and Closeable targets. */
  private static class SpyAppendable implements Appendable, Flushable, Closeable {
    boolean flushed;
    boolean closed;
    StringBuilder result = new StringBuilder();

    @Override
    public Appendable append(CharSequence csq) {
      result.append(csq);

            

Reported by PMD.

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

Line: 35

                private static class SpyAppendable implements Appendable, Flushable, Closeable {
    boolean flushed;
    boolean closed;
    StringBuilder result = new StringBuilder();

    @Override
    public Appendable append(CharSequence csq) {
      result.append(csq);
      return this;

            

Reported by PMD.

StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).
Design

Line: 35

                private static class SpyAppendable implements Appendable, Flushable, Closeable {
    boolean flushed;
    boolean closed;
    StringBuilder result = new StringBuilder();

    @Override
    public Appendable append(CharSequence csq) {
      result.append(csq);
      return this;

            

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

                  }
  }

  public void testWriteMethods() throws IOException {
    StringBuilder builder = new StringBuilder();
    Writer writer = new AppendableWriter(builder);

    writer.write("Hello".toCharArray());
    writer.write(',');

            

Reported by PMD.

Ensure that resources like this AppendableWriter object are closed after use
Error

Line: 68

              
  public void testWriteMethods() throws IOException {
    StringBuilder builder = new StringBuilder();
    Writer writer = new AppendableWriter(builder);

    writer.write("Hello".toCharArray());
    writer.write(',');
    writer.write(0xBEEF0020); // only lower 16 bits are important
    writer.write("Wo");

            

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

                  assertEquals("Hello, World!", builder.toString());
  }

  public void testAppendMethods() throws IOException {
    StringBuilder builder = new StringBuilder();
    Writer writer = new AppendableWriter(builder);

    writer.append("Hello,");
    writer.append(' ');

            

Reported by PMD.

Ensure that resources like this AppendableWriter object are closed after use
Error

Line: 82

              
  public void testAppendMethods() throws IOException {
    StringBuilder builder = new StringBuilder();
    Writer writer = new AppendableWriter(builder);

    writer.append("Hello,");
    writer.append(' ');
    writer.append("The World Wide Web", 4, 9);
    writer.append("!");

            

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

                  assertEquals("Hello, World!", builder.toString());
  }

  public void testCloseFlush() throws IOException {
    SpyAppendable spy = new SpyAppendable();
    Writer writer = new AppendableWriter(spy);

    writer.write("Hello");
    assertFalse(spy.flushed);

            

Reported by PMD.

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

Line: 92

                  assertEquals("Hello, World!", builder.toString());
  }

  public void testCloseFlush() throws IOException {
    SpyAppendable spy = new SpyAppendable();
    Writer writer = new AppendableWriter(spy);

    writer.write("Hello");
    assertFalse(spy.flushed);

            

Reported by PMD.

android/guava-tests/test/com/google/common/io/LineBufferTest.java
13 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: 38

              @AndroidIncompatible // occasionally very slow
public class LineBufferTest extends IoTestCase {

  public void testProcess() throws IOException {
    bufferHelper("");
    bufferHelper("\n", "\n");
    bufferHelper("\r\n", "\r\n");
    bufferHelper("\n\r", "\n", "\r");
    bufferHelper("\r", "\r");

            

Reported by PMD.

The String literal '\r\n' appears 4 times in this file; the first occurrence is on line 41
Error

Line: 41

                public void testProcess() throws IOException {
    bufferHelper("");
    bufferHelper("\n", "\n");
    bufferHelper("\r\n", "\r\n");
    bufferHelper("\n\r", "\n", "\r");
    bufferHelper("\r", "\r");
    bufferHelper("\n\n", "\n", "\n");
    bufferHelper("\r\n\r\n", "\r\n", "\r\n");
    bufferHelper("\r\r", "\r", "\r");

            

Reported by PMD.

Avoid reassigning the loop control variable 'chunk'
Design

Line: 72

                          });

    for (int chunk : CHUNK_SIZES) {
      chunk = Math.max(1, Math.min(chunk, input.length()));
      assertEquals(expectProcess, bufferHelper(input, chunk));
      assertEquals(expectRead, readUsingJava(input, chunk));
      assertEquals(expectRead, readUsingReader(input, chunk, true));
      assertEquals(expectRead, readUsingReader(input, chunk, false));
    }

            

Reported by PMD.

Ensure that resources like this BufferedReader object are closed after use
Error

Line: 101

                }

  private static List<String> readUsingJava(String input, int chunk) throws IOException {
    BufferedReader r = new BufferedReader(getChunkedReader(input, chunk));
    List<String> lines = Lists.newArrayList();
    String line;
    while ((line = r.readLine()) != null) {
      lines.add(line);
    }

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 104

                  BufferedReader r = new BufferedReader(getChunkedReader(input, chunk));
    List<String> lines = Lists.newArrayList();
    String line;
    while ((line = r.readLine()) != null) {
      lines.add(line);
    }
    r.close();
    return lines;
  }

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 118

                  LineReader r = new LineReader(readable);
    List<String> lines = Lists.newArrayList();
    String line;
    while ((line = r.readLine()) != null) {
      lines.add(line);
    }
    return lines;
  }


            

Reported by PMD.

Ensure that resources like this Reader object are closed after use
Error

Line: 126

              
  // Returns a Readable that is *not* a Reader.
  private static Readable getChunkedReadable(String input, int chunk) {
    final Reader reader = getChunkedReader(input, chunk);
    return new Readable() {
      @Override
      public int read(CharBuffer cbuf) throws IOException {
        return reader.read(cbuf);
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'expectRead' (lines '61'-'78').
Error

Line: 61

                private static void bufferHelper(String input, String... expect) throws IOException {

    List<String> expectProcess = Arrays.asList(expect);
    List<String> expectRead =
        Lists.transform(
            expectProcess,
            new Function<String, String>() {
              @Override
              public String apply(String value) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'expectRead' (lines '61'-'78').
Error

Line: 61

                private static void bufferHelper(String input, String... expect) throws IOException {

    List<String> expectProcess = Arrays.asList(expect);
    List<String> expectRead =
        Lists.transform(
            expectProcess,
            new Function<String, String>() {
              @Override
              public String apply(String value) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'line' (lines '104'-'109').
Error

Line: 104

                  BufferedReader r = new BufferedReader(getChunkedReader(input, chunk));
    List<String> lines = Lists.newArrayList();
    String line;
    while ((line = r.readLine()) != null) {
      lines.add(line);
    }
    r.close();
    return lines;
  }

            

Reported by PMD.

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

Line: 33

              @GwtCompatible
public class SampleElements<E> implements Iterable<E> {
  // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;


            

Reported by PMD.

Field e0 has the same name as a method
Error

Line: 33

              @GwtCompatible
public class SampleElements<E> implements Iterable<E> {
  // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;


            

Reported by PMD.

Field e1 has the same name as a method
Error

Line: 34

              public class SampleElements<E> implements Iterable<E> {
  // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {

            

Reported by PMD.

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

Line: 34

              public class SampleElements<E> implements Iterable<E> {
  // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {

            

Reported by PMD.

Field e2 has the same name as a method
Error

Line: 35

                // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;

            

Reported by PMD.

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

Line: 35

                // TODO: rename e3, e4 => missing1, missing2
  private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;

            

Reported by PMD.

Field e3 has the same name as a method
Error

Line: 36

                private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;
    this.e1 = e1;

            

Reported by PMD.

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

Line: 36

                private final E e0;
  private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;
    this.e1 = e1;

            

Reported by PMD.

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

Line: 37

                private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;
    this.e1 = e1;
    this.e2 = e2;

            

Reported by PMD.

Field e4 has the same name as a method
Error

Line: 37

                private final E e1;
  private final E e2;
  private final E e3;
  private final E e4;

  public SampleElements(E e0, E e1, E e2, E e3, E e4) {
    this.e0 = e0;
    this.e1 = e1;
    this.e2 = e2;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java
13 issues
This class has too many methods, consider refactoring it.
Design

Line: 50

               * @author Kevin Bourrillion
 */
@GwtIncompatible
public class TestsForListsInJavaUtil {
  public static Test suite() {
    return new TestsForListsInJavaUtil().allTests();
  }

  public Test allTests() {

            

Reported by PMD.

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

Line: 51

               */
@GwtIncompatible
public class TestsForListsInJavaUtil {
  public static Test suite() {
    return new TestsForListsInJavaUtil().allTests();
  }

  public Test allTests() {
    TestSuite suite = new TestSuite("java.util Lists");

            

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

                  return Collections.emptySet();
  }

  public Test testsForEmptyList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return Collections.emptyList();

            

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

                      .createTestSuite();
  }

  public Test testsForSingletonList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return Collections.singletonList(elements[0]);

            

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

                      .createTestSuite();
  }

  public Test testsForArraysAsList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return Arrays.asList(elements.clone());

            

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

                      .createTestSuite();
  }

  public Test testsForArrayList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return new ArrayList<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForLinkedList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return new LinkedList<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForCopyOnWriteArrayList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                return new CopyOnWriteArrayList<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForUnmodifiableList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                List<String> innerList = new ArrayList<>();

            

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

                      .createTestSuite();
  }

  public Test testsForCheckedList() {
    return ListTestSuiteBuilder.using(
            new TestStringListGenerator() {
              @Override
              public List<String> create(String[] elements) {
                List<String> innerList = new ArrayList<>();

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapEqualsTester.java
13 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 MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEqualsTrue() {
    new EqualsTester()
        .addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }


            

Reported by PMD.

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

Line: 42

              public class MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEqualsTrue() {
    new EqualsTester()
        .addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }

  public void testEqualsFalse() {
    List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());

            

Reported by PMD.

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

Line: 42

              public class MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEqualsTrue() {
    new EqualsTester()
        .addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
        .testEquals();
  }

  public void testEqualsFalse() {
    List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());

            

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

                      .testEquals();
  }

  public void testEqualsFalse() {
    List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());
    targetEntries.add(Helpers.mapEntry(k0(), v3()));
    new EqualsTester()
        .addEqualityGroup(multimap())
        .addEqualityGroup(getSubjectGenerator().create(targetEntries.toArray()))

            

Reported by PMD.

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

Line: 51

                  targetEntries.add(Helpers.mapEntry(k0(), v3()));
    new EqualsTester()
        .addEqualityGroup(multimap())
        .addEqualityGroup(getSubjectGenerator().create(targetEntries.toArray()))
        .testEquals();
  }

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

            

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

                      .testEquals();
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testEqualsMultimapWithNullKey() {
    Multimap<K, V> original = multimap();
    initMultimapWithNullKey();
    Multimap<K, V> withNull = multimap();

            

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

                      .testEquals();
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testEqualsMultimapWithNullValue() {
    Multimap<K, V> original = multimap();
    initMultimapWithNullValue();
    Multimap<K, V> withNull = multimap();

            

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

                      .testEquals();
  }

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

            

Reported by PMD.

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

Line: 85

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

  public void testHashCodeMatchesAsMap() {
    assertEquals(multimap().asMap().hashCode(), multimap().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: 89

                      .testEquals();
  }

  public void testHashCodeMatchesAsMap() {
    assertEquals(multimap().asMap().hashCode(), multimap().hashCode());
  }
}

            

Reported by PMD.

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

Line: 56

                  abstract Executor executor();
  }

  @Param Impl impl;
  Executor executor;

  static final class CountingRunnable implements Runnable {
    AtomicInteger integer = new AtomicInteger();


            

Reported by PMD.

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

Line: 57

                }

  @Param Impl impl;
  Executor executor;

  static final class CountingRunnable implements Runnable {
    AtomicInteger integer = new AtomicInteger();

    @Override

            

Reported by PMD.

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

Line: 60

                Executor executor;

  static final class CountingRunnable implements Runnable {
    AtomicInteger integer = new AtomicInteger();

    @Override
    public void run() {
      integer.incrementAndGet();
    }

            

Reported by PMD.

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

Line: 68

                  }
  }

  CountingRunnable countingRunnable = new CountingRunnable();

  Set<Thread> threads = new HashSet<>();

  @BeforeExperiment
  void before() {

            

Reported by PMD.

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

Line: 70

              
  CountingRunnable countingRunnable = new CountingRunnable();

  Set<Thread> threads = new HashSet<>();

  @BeforeExperiment
  void before() {
    executor = impl.executor();
    for (int i = 0; i < 4; i++) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 77

                  executor = impl.executor();
    for (int i = 0; i < 4; i++) {
      Thread thread =
          new Thread() {
            @Override
            public void run() {
              CountingRunnable localRunnable = new CountingRunnable();
              while (!isInterrupted()) {
                executor.execute(localRunnable);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 80

                        new Thread() {
            @Override
            public void run() {
              CountingRunnable localRunnable = new CountingRunnable();
              while (!isInterrupted()) {
                executor.execute(localRunnable);
              }
              countingRunnable.integer.addAndGet(localRunnable.integer.get());
            }

            

Reported by PMD.

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

Line: 84

                            while (!isInterrupted()) {
                executor.execute(localRunnable);
              }
              countingRunnable.integer.addAndGet(localRunnable.integer.get());
            }
          };
      threads.add(thread);
    }
  }

            

Reported by PMD.

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

Line: 84

                            while (!isInterrupted()) {
                executor.execute(localRunnable);
              }
              countingRunnable.integer.addAndGet(localRunnable.integer.get());
            }
          };
      threads.add(thread);
    }
  }

            

Reported by PMD.

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

Line: 111

                  for (int i = 0; i < reps; i++) {
      executor.execute(countingRunnable);
    }
    return countingRunnable.integer.get();
  }

  @Benchmark
  int timeContendedExecute(int reps) {
    final Executor executor = this.executor;

            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java
13 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

                 * Constructs two trivial HashFunctions (output := input), one streaming and one non-streaming,
   * and checks that their results are identical, no matter which newHasher version we used.
   */
  public void testExhaustive() {
    List<Hasher> hashers =
        ImmutableList.of(
            new StreamingVersion().newHasher(),
            new StreamingVersion().newHasher(52),
            new NonStreamingVersion().newHasher(),

            

Reported by PMD.

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

Line: 43

                          new NonStreamingVersion().newHasher(123));
    Random random = new Random(0);
    for (int i = 0; i < 200; i++) {
      RandomHasherAction.pickAtRandom(random).performAction(random, hashers);
    }
    HashCode[] codes = new HashCode[hashers.size()];
    for (int i = 0; i < hashers.size(); i++) {
      codes[i] = hashers.get(i).hash();
    }

            

Reported by PMD.

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

Line: 47

                  }
    HashCode[] codes = new HashCode[hashers.size()];
    for (int i = 0; i < hashers.size(); i++) {
      codes[i] = hashers.get(i).hash();
    }
    for (int i = 1; i < codes.length; i++) {
      assertEquals(codes[i - 1], codes[i]);
    }
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                    codes[i] = hashers.get(i).hash();
    }
    for (int i = 1; i < codes.length; i++) {
      assertEquals(codes[i - 1], codes[i]);
    }
  }

  public void testPutStringWithLowSurrogate() {
    // we pad because the dummy hash function we use to test this, merely copies the input into

            

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

                  }
  }

  public void testPutStringWithLowSurrogate() {
    // we pad because the dummy hash function we use to test this, merely copies the input into
    // the output, so the input must be at least 32 bits, since the output has to be that long
    assertPutString(new char[] {'p', HashTestUtils.randomLowSurrogate(new Random())});
  }


            

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

                  assertPutString(new char[] {'p', HashTestUtils.randomLowSurrogate(new Random())});
  }

  public void testPutStringWithHighSurrogate() {
    // we pad because the dummy hash function we use to test this, merely copies the input into
    // the output, so the input must be at least 32 bits, since the output has to be that long
    assertPutString(new char[] {'p', HashTestUtils.randomHighSurrogate(new Random())});
  }


            

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

                  assertPutString(new char[] {'p', HashTestUtils.randomHighSurrogate(new Random())});
  }

  public void testPutStringWithLowHighSurrogate() {
    assertPutString(
        new char[] {
          HashTestUtils.randomLowSurrogate(new Random()),
          HashTestUtils.randomHighSurrogate(new Random())
        });

            

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

                      });
  }

  public void testPutStringWithHighLowSurrogate() {
    assertPutString(
        new char[] {
          HashTestUtils.randomHighSurrogate(new Random()),
          HashTestUtils.randomLowSurrogate(new Random())
        });

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 91

                    h1.putChar(s.charAt(i));
    }
    h2.putUnencodedChars(s);
    assertEquals(h1.hash(), h2.hash());
  }

  static class StreamingVersion extends AbstractHashFunction {
    @Override
    public int bits() {

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 82

                      });
  }

  private static void assertPutString(char[] chars) {
    Hasher h1 = new NonStreamingVersion().newHasher();
    Hasher h2 = new NonStreamingVersion().newHasher();
    String s = new String(chars);
    // this is the correct implementation of the spec
    for (int i = 0; i < s.length(); i++) {

            

Reported by PMD.