The following issues were found

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

Line: 45

                      }
      };

  @Param private boolean useNew;

  @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;

            

Reported by PMD.

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

Line: 48

                @Param private boolean useNew;

  @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 50

                @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();

            

Reported by PMD.

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

Line: 51

                private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();
    for (int i = 0; i < OLD_WHITESPACE_TABLE.length(); i++) {

            

Reported by PMD.

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

Line: 53

                private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();
    for (int i = 0; i < OLD_WHITESPACE_TABLE.length(); i++) {
      bitSet.set(OLD_WHITESPACE_TABLE.charAt(i));
    }

            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 89

              
  private static String allMatchingChars(BitSet bitSet) {
    final char[] result = new char[bitSet.cardinality()];
    for (int j = 0, c = bitSet.nextSetBit(0); j < result.length; ++j) {
      result[j] = (char) c;
      c = bitSet.nextSetBit(c + 1);
    }
    return new String(result);
  }

            

Reported by PMD.

Avoid reassigning the loop control variable 'c'
Design

Line: 91

                  final char[] result = new char[bitSet.cardinality()];
    for (int j = 0, c = bitSet.nextSetBit(0); j < result.length; ++j) {
      result[j] = (char) c;
      c = bitSet.nextSetBit(c + 1);
    }
    return new String(result);
  }

  private static String newTestString(Random random, BitSet bitSet, int percentMatching) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'matcher' (lines '68'-'74').
Error

Line: 68

                @Benchmark
  public int countIn(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += matcher.countIn(teststring);
    }
    return result;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'teststring' (lines '69'-'74').
Error

Line: 69

                public int countIn(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += matcher.countIn(teststring);
    }
    return result;
  }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'matcher' (lines '79'-'85').
Error

Line: 79

                @Benchmark
  public int collapseFrom(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += System.identityHashCode(matcher.collapseFrom(teststring, ' '));
    }
    return result;

            

Reported by PMD.

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

Line: 32

              public class ToStringHelperBenchmark {

  @Param({"0", "1", "5"})
  int dataSize;

  @Param({"false", "true"})
  boolean omitNulls;

  enum Dataset {

            

Reported by PMD.

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

Line: 35

                int dataSize;

  @Param({"false", "true"})
  boolean omitNulls;

  enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 70

                          .addValue(Collections.singletonMap("k3", "v3"))
            .addValue(Collections.emptyMap())
            .addValue(null)
            .add(SHORT_NAME, java.util.Optional.of("1"))
            .add(LONG_NAME, java.util.Optional.of("1"))
            .add(SHORT_NAME, java.util.Optional.empty())
            .add(LONG_NAME, java.util.Optional.empty())
            .add(SHORT_NAME, Optional.of("2"))
            .add(SHORT_NAME, Optional.absent())

            

Reported by PMD.

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

Line: 71

                          .addValue(Collections.emptyMap())
            .addValue(null)
            .add(SHORT_NAME, java.util.Optional.of("1"))
            .add(LONG_NAME, java.util.Optional.of("1"))
            .add(SHORT_NAME, java.util.Optional.empty())
            .add(LONG_NAME, java.util.Optional.empty())
            .add(SHORT_NAME, Optional.of("2"))
            .add(SHORT_NAME, Optional.absent())
            .addValue(null)

            

Reported by PMD.

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

Line: 72

                          .addValue(null)
            .add(SHORT_NAME, java.util.Optional.of("1"))
            .add(LONG_NAME, java.util.Optional.of("1"))
            .add(SHORT_NAME, java.util.Optional.empty())
            .add(LONG_NAME, java.util.Optional.empty())
            .add(SHORT_NAME, Optional.of("2"))
            .add(SHORT_NAME, Optional.absent())
            .addValue(null)
            .add(SHORT_NAME, new int[] {1})

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java
14 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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListEqualsTester<E> extends AbstractListTester<E> {
  public void testEquals_otherListWithSameElements() {
    assertTrue(
        "A List should equal any other List containing the same elements.",
        getList().equals(new ArrayList<E>(getOrderedElements())));
  }


            

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

                      getList().equals(new ArrayList<E>(getOrderedElements())));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherListWithDifferentElements() {
    ArrayList<E> other = new ArrayList<>(getSampleElements());
    other.set(other.size() / 2, getSubjectGenerator().samples().e3());
    assertFalse(
        "A List should not equal another List containing different elements.",

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherListWithDifferentElements() {
    ArrayList<E> other = new ArrayList<>(getSampleElements());
    other.set(other.size() / 2, getSubjectGenerator().samples().e3());
    assertFalse(
        "A List should not equal another List containing different elements.",
        getList().equals(other));
  }


            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherListWithDifferentElements() {
    ArrayList<E> other = new ArrayList<>(getSampleElements());
    other.set(other.size() / 2, getSubjectGenerator().samples().e3());
    assertFalse(
        "A List should not equal another List containing different elements.",
        getList().equals(other));
  }


            

Reported by PMD.

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

Line: 50

                  other.set(other.size() / 2, getSubjectGenerator().samples().e3());
    assertFalse(
        "A List should not equal another List containing different elements.",
        getList().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherListContainingNull() {
    List<E> other = 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: 53

                      getList().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherListContainingNull() {
    List<E> other = new ArrayList<>(getSampleElements());
    other.set(other.size() / 2, null);
    assertFalse(
        "Two Lists should not be equal if exactly one of them has null at a given index.",

            

Reported by PMD.

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

Line: 59

                  other.set(other.size() / 2, null);
    assertFalse(
        "Two Lists should not be equal if exactly one of them has null at a given index.",
        getList().equals(other));
  }

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

            

Reported by PMD.

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

Line: 62

                      getList().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEquals_containingNull() {
    ArrayList<E> elements = new ArrayList<>(getSampleElements());
    elements.set(elements.size() / 2, null);
    collection = getSubjectGenerator().create(elements.toArray());

            

Reported by PMD.

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

Line: 67

                public void testEquals_containingNull() {
    ArrayList<E> elements = new ArrayList<>(getSampleElements());
    elements.set(elements.size() / 2, null);
    collection = getSubjectGenerator().create(elements.toArray());
    List<E> other = new ArrayList<>(getSampleElements());
    assertFalse(
        "Two Lists should not be equal if exactly one of them has null at a given index.",
        getList().equals(other));
  }

            

Reported by PMD.

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

Line: 71

                  List<E> other = new ArrayList<>(getSampleElements());
    assertFalse(
        "Two Lists should not be equal if exactly one of them has null at a given index.",
        getList().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_shorterList() {
    Collection<E> fewerElements = getSampleElements(getNumElements() - 1);

            

Reported by PMD.

guava-tests/benchmark/com/google/common/util/concurrent/AbstractFutureFootprintBenchmark.java
14 issues
The class 'AbstractFutureFootprintBenchmark' has a Standard Cyclomatic Complexity of 7 (Highest = 11).
Design

Line: 32

              import java.util.concurrent.Executor;

/** Measures the size of AbstractFuture implementations. */
public class AbstractFutureFootprintBenchmark {

  enum State {
    NOT_DONE,
    FINISHED,
    CANCELLED,

            

Reported by PMD.

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

Line: 41

                  FAILED
  }

  @Param State state;
  @Param Impl impl;

  @Param({"0", "1", "5", "10"})
  int numListeners;


            

Reported by PMD.

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

Line: 42

                }

  @Param State state;
  @Param Impl impl;

  @Param({"0", "1", "5", "10"})
  int numListeners;

  @Param({"0", "1", "5", "10"})

            

Reported by PMD.

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

Line: 45

                @Param Impl impl;

  @Param({"0", "1", "5", "10"})
  int numListeners;

  @Param({"0", "1", "5", "10"})
  int numThreads;

  private final Set<Thread> blockedThreads = new HashSet<>();

            

Reported by PMD.

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

Line: 48

                int numListeners;

  @Param({"0", "1", "5", "10"})
  int numThreads;

  private final Set<Thread> blockedThreads = new HashSet<>();

  @BeforeExperiment
  void setUp() throws Exception {

            

Reported by PMD.

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

Line: 50

                @Param({"0", "1", "5", "10"})
  int numThreads;

  private final Set<Thread> blockedThreads = new HashSet<>();

  @BeforeExperiment
  void setUp() throws Exception {
    if (state != State.NOT_DONE && (numListeners != 0 || numThreads != 0)) {
      throw new SkipThisScenarioException();

            

Reported by PMD.

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

Line: 52

              
  private final Set<Thread> blockedThreads = new HashSet<>();

  @BeforeExperiment
  void setUp() throws Exception {
    if (state != State.NOT_DONE && (numListeners != 0 || numThreads != 0)) {
      throw new SkipThisScenarioException();
    }
  }

            

Reported by PMD.

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

Line: 53

                private final Set<Thread> blockedThreads = new HashSet<>();

  @BeforeExperiment
  void setUp() throws Exception {
    if (state != State.NOT_DONE && (numListeners != 0 || numThreads != 0)) {
      throw new SkipThisScenarioException();
    }
  }


            

Reported by PMD.

The method 'measureSize' has a Standard Cyclomatic Complexity of 11.
Design

Line: 63

                // larger than they are.
  @SuppressWarnings("FutureReturnValueIgnored")
  @Footprint(exclude = {Runnable.class, Executor.class, Thread.class, Exception.class})
  public Object measureSize() {
    for (Thread thread : blockedThreads) {
      thread.interrupt();
    }
    blockedThreads.clear();
    final Facade<Object> f = impl.newFacade();

            

Reported by PMD.

The method 'measureSize()' has a cyclomatic complexity of 10.
Design

Line: 63

                // larger than they are.
  @SuppressWarnings("FutureReturnValueIgnored")
  @Footprint(exclude = {Runnable.class, Executor.class, Thread.class, Exception.class})
  public Object measureSize() {
    for (Thread thread : blockedThreads) {
      thread.interrupt();
    }
    blockedThreads.clear();
    final Facade<Object> f = impl.newFacade();

            

Reported by PMD.

guava-tests/test/com/google/common/primitives/FloatArrayAsListTest.java
14 issues
This class name ends with Test but contains no test cases
Error

Line: 41

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class FloatArrayAsListTest extends TestCase {

  private static List<Float> asList(Float[] values) {
    float[] temp = new float[values.length];
    for (int i = 0; i < values.length; i++) {
      temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).

            

Reported by PMD.

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

Line: 51

                  return Floats.asList(temp);
  }

  @GwtIncompatible // suite
  public static Test suite() {
    List<ListTestSuiteBuilder<Float>> builders =
        ImmutableList.of(
            ListTestSuiteBuilder.using(new FloatsAsListGenerator()).named("Floats.asList"),
            ListTestSuiteBuilder.using(new FloatsAsListHeadSubListGenerator())

            

Reported by PMD.

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

Line: 66

                  TestSuite suite = new TestSuite();
    for (ListTestSuiteBuilder<Float> builder : builders) {
      suite.addTest(
          builder
              .withFeatures(
                  CollectionSize.ONE,
                  CollectionSize.SEVERAL,
                  CollectionFeature.RESTRICTS_ELEMENTS,
                  ListFeature.SUPPORTS_SET)

            

Reported by PMD.

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

Line: 92

                  protected List<Float> create(Float[] elements) {
      Float[] suffix = {Float.MIN_VALUE, Float.MAX_VALUE};
      Float[] all = concat(elements, suffix);
      return asList(all).subList(0, elements.length);
    }
  }

  public static final class FloatsAsListTailSubListGenerator extends TestFloatListGenerator {
    @Override

            

Reported by PMD.

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

Line: 101

                  protected List<Float> create(Float[] elements) {
      Float[] prefix = {(float) 86, (float) 99};
      Float[] all = concat(prefix, elements);
      return asList(all).subList(2, elements.length + 2);
    }
  }

  public static final class FloatsAsListMiddleSubListGenerator extends TestFloatListGenerator {
    @Override

            

Reported by PMD.

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

Line: 111

                    Float[] prefix = {Float.MIN_VALUE, Float.MAX_VALUE};
      Float[] suffix = {(float) 86, (float) 99};
      Float[] all = concat(concat(prefix, elements), suffix);
      return asList(all).subList(2, elements.length + 2);
    }
  }

  private static Float[] concat(Float[] left, Float[] right) {
    Float[] result = new Float[left.length + right.length];

            

Reported by PMD.

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

Line: 43

              @GwtCompatible(emulated = true)
public class FloatArrayAsListTest extends TestCase {

  private static List<Float> asList(Float[] values) {
    float[] temp = new float[values.length];
    for (int i = 0; i < values.length; i++) {
      temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
    }
    return Floats.asList(temp);

            

Reported by PMD.

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

Line: 115

                  }
  }

  private static Float[] concat(Float[] left, Float[] right) {
    Float[] result = new Float[left.length + right.length];
    System.arraycopy(left, 0, result, 0, left.length);
    System.arraycopy(right, 0, result, left.length, right.length);
    return result;
  }

            

Reported by PMD.

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

Line: 142

                   * Creates a new collection containing the given elements; implement this method instead of
     * {@link #create(Object...)}.
     */
    protected abstract List<Float> create(Float[] elements);

    @Override
    public Float[] createArray(int length) {
      return new Float[length];
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'temp' (lines '44'-'46').
Error

Line: 44

              public class FloatArrayAsListTest extends TestCase {

  private static List<Float> asList(Float[] values) {
    float[] temp = new float[values.length];
    for (int i = 0; i < values.length; i++) {
      temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
    }
    return Floats.asList(temp);
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java
14 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: 43

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListRemoveAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_unsupported() {
    try {
      getList().remove(0);
      fail("remove(i) should throw");

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_unsupported() {
    try {
      getList().remove(0);
      fail("remove(i) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_negative() {
    try {
      getList().remove(-1);
      fail("remove(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {

            

Reported by PMD.

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

Line: 57

                @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_negative() {
    try {
      getList().remove(-1);
      fail("remove(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_tooLarge() {
    try {
      getList().remove(getNumElements());
      fail("remove(size) should throw");
    } catch (IndexOutOfBoundsException expected) {

            

Reported by PMD.

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

Line: 67

                @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_tooLarge() {
    try {
      getList().remove(getNumElements());
      fail("remove(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_first() {
    runRemoveTest(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: 80

                  runRemoveTest(0);
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testRemoveAtIndex_middle() {
    runRemoveTest(getNumElements() / 2);
  }


            

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

                  runRemoveTest(getNumElements() / 2);
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();

            

Reported by PMD.

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

Line: 92

                public void testRemoveAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().remove(getNumElements() / 2);
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success
    }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java
14 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: 43

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListRemoveAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_unsupported() {
    try {
      getList().remove(0);
      fail("remove(i) should throw");

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_unsupported() {
    try {
      getList().remove(0);
      fail("remove(i) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_negative() {
    try {
      getList().remove(-1);
      fail("remove(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {

            

Reported by PMD.

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

Line: 57

                @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_negative() {
    try {
      getList().remove(-1);
      fail("remove(-1) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_tooLarge() {
    try {
      getList().remove(getNumElements());
      fail("remove(size) should throw");
    } catch (IndexOutOfBoundsException expected) {

            

Reported by PMD.

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

Line: 67

                @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  public void testRemoveAtIndex_tooLarge() {
    try {
      getList().remove(getNumElements());
      fail("remove(size) should throw");
    } catch (IndexOutOfBoundsException expected) {
    }
    expectUnchanged();
  }

            

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

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndex_first() {
    runRemoveTest(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: 80

                  runRemoveTest(0);
  }

  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testRemoveAtIndex_middle() {
    runRemoveTest(getNumElements() / 2);
  }


            

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

                  runRemoveTest(getNumElements() / 2);
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();

            

Reported by PMD.

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

Line: 92

                public void testRemoveAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().remove(getNumElements() / 2);
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success
    }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java
14 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 MapContainsValueTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testContains_yes() {
    assertTrue("containsValue(present) should return true", getMap().containsValue(v0()));
  }

  public void testContains_no() {

            

Reported by PMD.

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

Line: 42

              public class MapContainsValueTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testContains_yes() {
    assertTrue("containsValue(present) should return true", getMap().containsValue(v0()));
  }

  public void testContains_no() {
    assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

            

Reported by PMD.

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

Line: 45

                  assertTrue("containsValue(present) should return true", getMap().containsValue(v0()));
  }

  public void testContains_no() {
    assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedButAllowed() {

            

Reported by PMD.

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

Line: 46

                }

  public void testContains_no() {
    assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedButAllowed() {
    assertFalse("containsValue(null) should return false", getMap().containsValue(null));

            

Reported by PMD.

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

Line: 49

                  assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedButAllowed() {
    assertFalse("containsValue(null) should return false", getMap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)

            

Reported by PMD.

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

Line: 51

              
  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedButAllowed() {
    assertFalse("containsValue(null) should return false", getMap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedAndUnsupported() {
    expectNullValueMissingWhenNullValuesUnsupported(

            

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

                  assertFalse("containsValue(null) should return false", getMap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
  public void testContains_nullNotContainedAndUnsupported() {
    expectNullValueMissingWhenNullValuesUnsupported(
        "containsValue(null) should return false or throw");
  }


            

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

                      "containsValue(null) should return false or throw");
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nonNullWhenNullContained() {
    initMapWithNullValue();
    assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

            

Reported by PMD.

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

Line: 64

                @CollectionSize.Require(absent = ZERO)
  public void testContains_nonNullWhenNullContained() {
    initMapWithNullValue();
    assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nullContained() {

            

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

                  assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nullContained() {
    initMapWithNullValue();
    assertTrue("containsValue(null) should return true", getMap().containsValue(null));
  }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java
14 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: 44

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionContainsAllTester<E> extends AbstractCollectionTester<E> {
  public void testContainsAll_empty() {
    assertTrue(
        "containsAll(empty) should return true", collection.containsAll(MinimalCollection.of()));
  }

  @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: 49

                      "containsAll(empty) should return true", collection.containsAll(MinimalCollection.of()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testContainsAll_subset() {
    assertTrue(
        "containsAll(subset) should return true",
        collection.containsAll(MinimalCollection.of(e0())));
  }

            

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

                      collection.containsAll(MinimalCollection.of(e0())));
  }

  public void testContainsAll_sameElements() {
    assertTrue(
        "containsAll(sameElements) should return true",
        collection.containsAll(MinimalCollection.of(createSamplesArray())));
  }


            

Reported by PMD.

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

Line: 62

                      collection.containsAll(MinimalCollection.of(createSamplesArray())));
  }

  @SuppressWarnings("ModifyingCollectionWithItself")
  public void testContainsAll_self() {
    assertTrue("containsAll(this) should return true", collection.containsAll(collection));
  }

  public void testContainsAll_partialOverlap() {

            

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

                  assertTrue("containsAll(this) should return true", collection.containsAll(collection));
  }

  public void testContainsAll_partialOverlap() {
    assertFalse(
        "containsAll(partialOverlap) should return false",
        collection.containsAll(MinimalCollection.of(e0(), e3())));
  }


            

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

                      collection.containsAll(MinimalCollection.of(e0(), e3())));
  }

  public void testContainsAll_disjoint() {
    assertFalse(
        "containsAll(disjoint) should return false",
        collection.containsAll(MinimalCollection.of(e3())));
  }


            

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

                      collection.containsAll(MinimalCollection.of(e3())));
  }

  @CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
  public void testContainsAll_nullNotAllowed() {
    try {
      assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
    } catch (NullPointerException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 83

                public void testContainsAll_nullNotAllowed() {
    try {
      assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
  public void testContainsAll_nullAllowed() {

            

Reported by PMD.

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

Line: 83

                public void testContainsAll_nullNotAllowed() {
    try {
      assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
  public void testContainsAll_nullAllowed() {

            

Reported by PMD.

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

Line: 83

                public void testContainsAll_nullNotAllowed() {
    try {
      assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
  public void testContainsAll_nullAllowed() {

            

Reported by PMD.

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

Line: 45

                      }
      };

  @Param private boolean useNew;

  @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;

            

Reported by PMD.

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

Line: 48

                @Param private boolean useNew;

  @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 50

                @Param({"20", "50", "80"})
  private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();

            

Reported by PMD.

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

Line: 51

                private int percentMatching;

  private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();
    for (int i = 0; i < OLD_WHITESPACE_TABLE.length(); i++) {

            

Reported by PMD.

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

Line: 53

                private String teststring;
  private CharMatcher matcher;

  @BeforeExperiment
  protected void setUp() {
    BitSet bitSet = new BitSet();
    for (int i = 0; i < OLD_WHITESPACE_TABLE.length(); i++) {
      bitSet.set(OLD_WHITESPACE_TABLE.charAt(i));
    }

            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 89

              
  private static String allMatchingChars(BitSet bitSet) {
    final char[] result = new char[bitSet.cardinality()];
    for (int j = 0, c = bitSet.nextSetBit(0); j < result.length; ++j) {
      result[j] = (char) c;
      c = bitSet.nextSetBit(c + 1);
    }
    return new String(result);
  }

            

Reported by PMD.

Avoid reassigning the loop control variable 'c'
Design

Line: 91

                  final char[] result = new char[bitSet.cardinality()];
    for (int j = 0, c = bitSet.nextSetBit(0); j < result.length; ++j) {
      result[j] = (char) c;
      c = bitSet.nextSetBit(c + 1);
    }
    return new String(result);
  }

  private static String newTestString(Random random, BitSet bitSet, int percentMatching) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'matcher' (lines '68'-'74').
Error

Line: 68

                @Benchmark
  public int countIn(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += matcher.countIn(teststring);
    }
    return result;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'teststring' (lines '69'-'74').
Error

Line: 69

                public int countIn(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += matcher.countIn(teststring);
    }
    return result;
  }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'matcher' (lines '79'-'85').
Error

Line: 79

                @Benchmark
  public int collapseFrom(int reps) {
    int result = 0;
    CharMatcher matcher = this.matcher;
    String teststring = this.teststring;
    for (int i = 0; i < reps; i++) {
      result += System.identityHashCode(matcher.collapseFrom(teststring, ' '));
    }
    return result;

            

Reported by PMD.