The following issues were found

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

Line: 41

               */
public class ForwardingQueueTest extends TestCase {

  static final class StandardImplForwardingQueue<T> extends ForwardingQueue<T> {
    private final Queue<T> backingQueue;

    StandardImplForwardingQueue(Queue<T> backingQueue) {
      this.backingQueue = backingQueue;
    }

            

Reported by PMD.

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

Line: 42

              public class ForwardingQueueTest extends TestCase {

  static final class StandardImplForwardingQueue<T> extends ForwardingQueue<T> {
    private final Queue<T> backingQueue;

    StandardImplForwardingQueue(Queue<T> backingQueue) {
      this.backingQueue = backingQueue;
    }


            

Reported by PMD.

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

Line: 119

                  }
  }

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

    suite.addTestSuite(ForwardingQueueTest.class);
    suite.addTest(
        QueueTestSuiteBuilder.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: 142

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 143

                }

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

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java
5 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 39

              public class ListLastIndexOfTester<E> extends AbstractListIndexOfTester<E> {
  @Override
  protected int find(Object o) {
    return getList().lastIndexOf(o);
  }

  @Override
  protected String getMethodName() {
    return "lastIndexOf";

            

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

                  return "lastIndexOf";
  }

  @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);

            

Reported by PMD.

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

Line: 52

                public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,
        getList().lastIndexOf(e0()));
  }

            

Reported by PMD.

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

Line: 56

                  assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,
        getList().lastIndexOf(e0()));
  }
}

            

Reported by PMD.

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

Line: 50

                @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java
5 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 39

              public class ListIndexOfTester<E> extends AbstractListIndexOfTester<E> {
  @Override
  protected int find(Object o) {
    return getList().indexOf(o);
  }

  @Override
  protected String getMethodName() {
    return "indexOf";

            

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

                  return "indexOf";
  }

  @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);

            

Reported by PMD.

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

Line: 52

                public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }
}

            

Reported by PMD.

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

Line: 54

                  array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }
}

            

Reported by PMD.

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

Line: 50

                @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0()));
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java
5 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(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetAddTester<E> extends AbstractSetTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedPresent() {
    assertFalse("add(present) should return false", getSet().add(e0()));
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 43

                @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedPresent() {
    assertFalse("add(present) should return false", getSet().add(e0()));
    expectUnchanged();
  }

  @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 47

                  expectUnchanged();
  }

  @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertFalse("add(nullPresent) should return false", getSet().add(null));

            

Reported by PMD.

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

Line: 51

                @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertFalse("add(nullPresent) should return false", getSet().add(null));
    expectContents(array);
  }

  /**

            

Reported by PMD.

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

Line: 52

                public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertFalse("add(nullPresent) should return false", getSet().add(null));
    expectContents(array);
  }

  /**
   * Returns the {@link Method} instance for {@link #testAdd_supportedNullPresent()} so that tests

            

Reported by PMD.

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

Line: 35

                  "3", "6", "11", "23", "45", "91", "181", "362", "724", "1448", "2896", "5793", "11585", "23170",
    "46341", "92682", "185364", "370728", "741455", "1482910", "2965821", "5931642"
  })
  private int size;

  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;


            

Reported by PMD.

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

Line: 39

              
  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp

            

Reported by PMD.

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

Line: 42

                private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp
  private CollectionBenchmarkSampleData sampleData;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 45

                private SetImpl impl;

  // the following must be set during setUp
  private CollectionBenchmarkSampleData sampleData;

  @BeforeExperiment
  void setUp() {
    sampleData = new CollectionBenchmarkSampleData(true, random, 0.8, 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: 47

                // the following must be set during setUp
  private CollectionBenchmarkSampleData sampleData;

  @BeforeExperiment
  void setUp() {
    sampleData = new CollectionBenchmarkSampleData(true, random, 0.8, size);
  }

  @Benchmark

            

Reported by PMD.

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

Line: 36

                  "3", "6", "11", "23", "45", "91", "181", "362", "724", "1448", "2896", "5793", "11585", "23170",
    "46341", "92682", "185364", "370728", "741455", "1482910", "2965821", "5931642"
  })
  private int size;

  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;


            

Reported by PMD.

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

Line: 40

              
  // "" means no fixed seed
  @Param("1234")
  private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp

            

Reported by PMD.

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

Line: 43

                private SpecialRandom random;

  @Param({"ImmutableSetImpl", "HashSetImpl"})
  private SetImpl impl;

  // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 46

                private SetImpl impl;

  // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment
  void setUp() {
    CollectionBenchmarkSampleData sampleData =
        new CollectionBenchmarkSampleData(true, random, 0.8, 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: 48

                // the following must be set during setUp
  private Set<Element> setToTest;

  @BeforeExperiment
  void setUp() {
    CollectionBenchmarkSampleData sampleData =
        new CollectionBenchmarkSampleData(true, random, 0.8, size);
    setToTest = (Set<Element>) impl.create(sampleData.getValuesInSet());
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java
5 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 31

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListGetTester<E> extends AbstractListTester<E> {
  public void testGet_valid() {
    // This calls get() on each index and checks the result:
    expectContents(createOrderedArray());
  }

  public void testGet_negative() {

            

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

                  expectContents(createOrderedArray());
  }

  public void testGet_negative() {
    try {
      getList().get(-1);
      fail("get(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }

            

Reported by PMD.

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

Line: 38

              
  public void testGet_negative() {
    try {
      getList().get(-1);
      fail("get(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
  }


            

Reported by PMD.

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

Line: 44

                  }
  }

  public void testGet_tooLarge() {
    try {
      getList().get(getNumElements());
      fail("get(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }

            

Reported by PMD.

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

Line: 46

              
  public void testGet_tooLarge() {
    try {
      getList().get(getNumElements());
      fail("get(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/testing/ClusterException.java
5 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 62

               * @author Luiz-Otavio Zorzella
 */
@GwtCompatible
final class ClusterException extends RuntimeException {

  public final Collection<? extends Throwable> exceptions;

  private ClusterException(Collection<? extends Throwable> exceptions) {
    super(

            

Reported by PMD.

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

Line: 64

              @GwtCompatible
final class ClusterException extends RuntimeException {

  public final Collection<? extends Throwable> exceptions;

  private ClusterException(Collection<? extends Throwable> exceptions) {
    super(
        exceptions.size() + " exceptions were thrown. The first exception is listed as a cause.",
        exceptions.iterator().next());

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 100

                 * @throws IllegalArgumentException if {@code exceptions} is empty
   */
  public static RuntimeException create(Collection<? extends Throwable> exceptions) {
    if (exceptions.size() == 0) {
      throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
    }
    if (exceptions.size() == 1) {
      Throwable temp = exceptions.iterator().next();
      if (temp instanceof RuntimeException) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 103

                  if (exceptions.size() == 0) {
      throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
    }
    if (exceptions.size() == 1) {
      Throwable temp = exceptions.iterator().next();
      if (temp instanceof RuntimeException) {
        return (RuntimeException) temp;
      } else {
        return new RuntimeException(temp);

            

Reported by PMD.

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

Line: 104

                    throw new IllegalArgumentException("Can't create an ExceptionCollection with no exceptions");
    }
    if (exceptions.size() == 1) {
      Throwable temp = exceptions.iterator().next();
      if (temp instanceof RuntimeException) {
        return (RuntimeException) temp;
      } else {
        return new RuntimeException(temp);
      }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java
5 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: 37

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetMultimapPutAllTester<K, V> extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {

  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutAllHandlesDuplicates() {
    @SuppressWarnings("unchecked")
    List<V> valuesToPut = Arrays.asList(v0(), v1(), v0());

    for (K k : sampleKeys()) {

            

Reported by PMD.

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

Line: 45

                  for (K k : sampleKeys()) {
      resetContainer();

      Set<V> expectedValues = copyToSet(multimap().get(k));

      multimap().putAll(k, valuesToPut);
      expectedValues.addAll(valuesToPut);

      assertGet(k, expectedValues);

            

Reported by PMD.

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

Line: 47

              
      Set<V> expectedValues = copyToSet(multimap().get(k));

      multimap().putAll(k, valuesToPut);
      expectedValues.addAll(valuesToPut);

      assertGet(k, expectedValues);
    }
  }

            

Reported by PMD.

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

Line: 48

                    Set<V> expectedValues = copyToSet(multimap().get(k));

      multimap().putAll(k, valuesToPut);
      expectedValues.addAll(valuesToPut);

      assertGet(k, expectedValues);
    }
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'valuesToPut' (lines '40'-'52').
Error

Line: 40

                @MapFeature.Require(SUPPORTS_PUT)
  public void testPutAllHandlesDuplicates() {
    @SuppressWarnings("unchecked")
    List<V> valuesToPut = Arrays.asList(v0(), v1(), v0());

    for (K k : sampleKeys()) {
      resetContainer();

      Set<V> expectedValues = copyToSet(multimap().get(k));

            

Reported by PMD.

guava-testlib/src/com/google/common/testing/TearDownStack.java
5 issues
Avoid using implementation types like 'LinkedList'; use the interface instead
Design

Line: 45

                private static final Logger logger = Logger.getLogger(TearDownStack.class.getName());

  @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;

            

Reported by PMD.

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

Line: 45

                private static final Logger logger = Logger.getLogger(TearDownStack.class.getName());

  @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;

            

Reported by PMD.

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

Line: 47

                @GuardedBy("stack")
  final LinkedList<TearDown> stack = new LinkedList<>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;
  }


            

Reported by PMD.

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

Line: 75

                  for (TearDown tearDown : stackCopy) {
      try {
        tearDown.tearDown();
      } catch (Throwable t) {
        if (suppressThrows) {
          logger.log(Level.INFO, "exception thrown during tearDown", t);
        } else {
          exceptions.add(t);
        }

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 83

                      }
      }
    }
    if (!suppressThrows && (exceptions.size() > 0)) {
      throw ClusterException.create(exceptions);
    }
  }
}

            

Reported by PMD.