The following issues were found

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

android/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.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: 39

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapContainsKeyTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testContains_yes() {
    assertTrue("containsKey(present) should return true", getMap().containsKey(k0()));
  }

  public void testContains_no() {

            

Reported by PMD.

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

Line: 41

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

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

            

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

                  assertTrue("containsKey(present) should return true", getMap().containsKey(k0()));
  }

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

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

            

Reported by PMD.

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

Line: 45

                }

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

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContains_nullNotContainedButAllowed() {
    assertFalse("containsKey(null) should return false", getMap().containsKey(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: 48

                  assertFalse("containsKey(notPresent) should return false", getMap().containsKey(k3()));
  }

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

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)

            

Reported by PMD.

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

Line: 50

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

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
  public void testContains_nullNotContainedAndUnsupported() {
    expectNullKeyMissingWhenNullKeysUnsupported("containsKey(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: 53

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

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
  public void testContains_nullNotContainedAndUnsupported() {
    expectNullKeyMissingWhenNullKeysUnsupported("containsKey(null) should return false or throw");
  }

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

                  expectNullKeyMissingWhenNullKeysUnsupported("containsKey(null) should return false or throw");
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nonNullWhenNullContained() {
    initMapWithNullKey();
    assertFalse("containsKey(notPresent) should return false", getMap().containsKey(k3()));
  }

            

Reported by PMD.

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

Line: 62

                @CollectionSize.Require(absent = ZERO)
  public void testContains_nonNullWhenNullContained() {
    initMapWithNullKey();
    assertFalse("containsKey(notPresent) should return false", getMap().containsKey(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @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: 65

                  assertFalse("containsKey(notPresent) should return false", getMap().containsKey(k3()));
  }

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

            

Reported by PMD.

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

Line: 89

                    for (UnhashableObject value : elements) {
        builder.put(key++, value);
      }
      return builder.build().values();
    }
  }

  public static class ImmutableMapKeyListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 100

                    for (int i = 0; i < elements.length; i++) {
        builder.put(elements[i], i);
      }
      return builder.build().keySet().asList();
    }
  }

  public static class ImmutableMapValueListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 100

                    for (int i = 0; i < elements.length; i++) {
        builder.put(elements[i], i);
      }
      return builder.build().keySet().asList();
    }
  }

  public static class ImmutableMapValueListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 111

                    for (int i = 0; i < elements.length; i++) {
        builder.put(i, elements[i]);
      }
      return builder.build().values().asList();
    }
  }

  public static class ImmutableMapEntryListGenerator
      implements TestListGenerator<Entry<String, Integer>> {

            

Reported by PMD.

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

Line: 111

                    for (int i = 0; i < elements.length; i++) {
        builder.put(i, elements[i]);
      }
      return builder.build().values().asList();
    }
  }

  public static class ImmutableMapEntryListGenerator
      implements TestListGenerator<Entry<String, Integer>> {

            

Reported by PMD.

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

Line: 128

                        mapEntry("toaster", -2));
    }

    @SuppressWarnings("unchecked")
    @Override
    public Entry<String, Integer>[] createArray(int length) {
      return new Entry[length];
    }


            

Reported by PMD.

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

Line: 147

                      Entry<String, Integer> entry = (Entry<String, Integer>) o;
        builder.put(entry);
      }
      return builder.build().entrySet().asList();
    }
  }

  public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator {
    @Override

            

Reported by PMD.

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

Line: 147

                      Entry<String, Integer> entry = (Entry<String, Integer>) o;
        builder.put(entry);
      }
      return builder.build().entrySet().asList();
    }
  }

  public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator {
    @Override

            

Reported by PMD.

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

Line: 179

              
        @Override
        public int compare(Entry<AnEnum, String> left, Entry<AnEnum, String> right) {
          return left.getKey().compareTo(right.getKey());
        }
      }.sortedCopy(insertionOrder);
    }
  }


            

Reported by PMD.

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

Line: 210

                    for (Object elem : elements) {
        @SuppressWarnings("unchecked") // safe by generator contract
        Entry<String, Collection<Integer>> entry = (Entry<String, Collection<Integer>>) elem;
        Integer value = Iterables.getOnlyElement(entry.getValue());
        builder.put(entry.getKey(), value);
      }
      return builder.build().asMultimap().asMap();
    }


            

Reported by PMD.

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

android/guava-tests/test/com/google/common/collect/CountTest.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: 27

               */
@GwtCompatible
public class CountTest extends TestCase {
  public void testGet() {
    assertEquals(20, new Count(20).get());
  }

  public void testGetAndAdd() {
    Count holder = new Count(20);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

              @GwtCompatible
public class CountTest extends TestCase {
  public void testGet() {
    assertEquals(20, new Count(20).get());
  }

  public void testGetAndAdd() {
    Count holder = new Count(20);
    assertEquals(20, holder.get());

            

Reported by PMD.

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

Line: 31

                  assertEquals(20, new Count(20).get());
  }

  public void testGetAndAdd() {
    Count holder = new Count(20);
    assertEquals(20, holder.get());
    holder.add(1);
    assertEquals(21, holder.get());
  }

            

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

                  assertEquals(20, new Count(20).get());
  }

  public void testGetAndAdd() {
    Count holder = new Count(20);
    assertEquals(20, holder.get());
    holder.add(1);
    assertEquals(21, holder.get());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              
  public void testGetAndAdd() {
    Count holder = new Count(20);
    assertEquals(20, holder.get());
    holder.add(1);
    assertEquals(21, holder.get());
  }

  public void testAddAndGet() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 35

                  Count holder = new Count(20);
    assertEquals(20, holder.get());
    holder.add(1);
    assertEquals(21, holder.get());
  }

  public void testAddAndGet() {
    Count holder = new Count(20);
    assertEquals(21, holder.addAndGet(1));

            

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

                  assertEquals(21, holder.get());
  }

  public void testAddAndGet() {
    Count holder = new Count(20);
    assertEquals(21, holder.addAndGet(1));
  }

  public void testGetAndSet() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

              
  public void testAddAndGet() {
    Count holder = new Count(20);
    assertEquals(21, holder.addAndGet(1));
  }

  public void testGetAndSet() {
    Count holder = new Count(10);
    assertEquals(10, holder.getAndSet(20));

            

Reported by PMD.

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

Line: 43

                  assertEquals(21, holder.addAndGet(1));
  }

  public void testGetAndSet() {
    Count holder = new Count(10);
    assertEquals(10, holder.getAndSet(20));
    assertEquals(20, holder.get());
  }


            

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

                  assertEquals(21, holder.addAndGet(1));
  }

  public void testGetAndSet() {
    Count holder = new Count(10);
    assertEquals(10, holder.getAndSet(20));
    assertEquals(20, holder.get());
  }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveAllTester.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 MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllAbsentKey() {
    assertEmpty(multimap().removeAll(k3()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 46

              public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllAbsentKey() {
    assertEmpty(multimap().removeAll(k3()));
    expectUnchanged();
  }

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

            

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

                  expectUnchanged();
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllPresentKey() {
    assertContentsAnyOrder(multimap().removeAll(k0()), v0());
    expectMissing(e0());
  }

            

Reported by PMD.

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

Line: 53

                @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllPresentKey() {
    assertContentsAnyOrder(multimap().removeAll(k0()), v0());
    expectMissing(e0());
  }

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

            

Reported by PMD.

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

Line: 57

                  expectMissing(e0());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllPropagatesToGet() {
    Collection<V> getResult = multimap().get(k0());

    multimap().removeAll(k0());

            

Reported by PMD.

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

Line: 60

                @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllPropagatesToGet() {
    Collection<V> getResult = multimap().get(k0());

    multimap().removeAll(k0());

    assertEmpty(getResult);
    expectMissing(e0());

            

Reported by PMD.

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

Line: 62

                public void testRemoveAllPropagatesToGet() {
    Collection<V> getResult = multimap().get(k0());

    multimap().removeAll(k0());

    assertEmpty(getResult);
    expectMissing(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: 68

                  expectMissing(e0());
  }

  @CollectionSize.Require(SEVERAL)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllMultipleValues() {
    resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2()));


            

Reported by PMD.

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

Line: 70

              
  @CollectionSize.Require(SEVERAL)
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAllMultipleValues() {
    resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2()));

    assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2());
    assertEmpty(multimap());

            

Reported by PMD.

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

Line: 74

                  resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k0(), v2()));

    assertContentsAnyOrder(multimap().removeAll(k0()), v0(), v1(), v2());
    assertEmpty(multimap());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS})

            

Reported by PMD.

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

Line: 54

                    String name, CharSinkFactory factory, String string, String desc) {
    TestSuite stringSuite = new TestSuite(name + " [" + desc + "]");
    for (final Method method : testMethods) {
      stringSuite.addTest(new CharSinkTester(factory, string, name, desc, method));
    }
    return stringSuite;
  }

  private final ImmutableList<String> lines;

            

Reported by PMD.

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

Line: 59

                  return stringSuite;
  }

  private final ImmutableList<String> lines;
  private final ImmutableList<String> expectedLines;

  private CharSink sink;

  public CharSinkTester(

            

Reported by PMD.

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

Line: 60

                }

  private final ImmutableList<String> lines;
  private final ImmutableList<String> expectedLines;

  private CharSink sink;

  public CharSinkTester(
      CharSinkFactory factory, String string, String suiteName, String caseDesc, Method method) {

            

Reported by PMD.

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

Line: 62

                private final ImmutableList<String> lines;
  private final ImmutableList<String> expectedLines;

  private CharSink sink;

  public CharSinkTester(
      CharSinkFactory factory, String string, String suiteName, String caseDesc, Method method) {
    super(factory, string, suiteName, caseDesc, method);
    this.lines = getLines(string);

            

Reported by PMD.

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

Line: 71

                  this.expectedLines = getLines(expected);
  }

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

  public void testOpenStream() throws IOException {

            

Reported by PMD.

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

Line: 76

                  this.sink = factory.createSink();
  }

  public void testOpenStream() throws IOException {
    Writer writer = sink.openStream();
    try {
      writer.write(data);
    } finally {
      writer.close();

            

Reported by PMD.

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

Line: 78

              
  public void testOpenStream() throws IOException {
    Writer writer = sink.openStream();
    try {
      writer.write(data);
    } finally {
      writer.close();
    }


            

Reported by PMD.

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

Line: 87

                  assertContainsExpectedString();
  }

  public void testOpenBufferedStream() throws IOException {
    Writer writer = sink.openBufferedStream();
    try {
      writer.write(data);
    } finally {
      writer.close();

            

Reported by PMD.

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

Line: 89

              
  public void testOpenBufferedStream() throws IOException {
    Writer writer = sink.openBufferedStream();
    try {
      writer.write(data);
    } finally {
      writer.close();
    }


            

Reported by PMD.

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

Line: 98

                  assertContainsExpectedString();
  }

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

    assertContainsExpectedString();
  }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/SafeTreeMap.java
13 issues
Avoid throwing null pointer exceptions.
Design

Line: 70

                private SafeTreeMap(NavigableMap<K, V> delegate) {
    this.delegate = delegate;
    if (delegate == null) {
      throw new NullPointerException();
    }
    for (K k : keySet()) {
      checkValid(k);
    }
  }

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 39

               * @author Louis Wasserman
 */
@GwtIncompatible
public final class SafeTreeMap<K, V> implements Serializable, NavigableMap<K, V> {
  @SuppressWarnings("unchecked")
  private static final Comparator<Object> NATURAL_ORDER =
      new Comparator<Object>() {
        @Override
        public int compare(Object o1, Object o2) {

            

Reported by PMD.

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

Line: 49

                      }
      };

  private final NavigableMap<K, V> delegate;

  public SafeTreeMap() {
    this(new TreeMap<K, V>());
  }


            

Reported by PMD.

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

Line: 106

                public boolean containsKey(Object key) {
    try {
      return delegate.containsKey(checkValid(key));
    } catch (NullPointerException | ClassCastException e) {
      return false;
    }
  }

  @Override

            

Reported by PMD.

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

Line: 106

                public boolean containsKey(Object key) {
    try {
      return delegate.containsKey(checkValid(key));
    } catch (NullPointerException | ClassCastException e) {
      return false;
    }
  }

  @Override

            

Reported by PMD.

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

Line: 136

                    @Override
      public boolean contains(Object object) {
        try {
          return delegate().contains(object);
        } catch (NullPointerException | ClassCastException e) {
          return false;
        }
      }


            

Reported by PMD.

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

Line: 137

                    public boolean contains(Object object) {
        try {
          return delegate().contains(object);
        } catch (NullPointerException | ClassCastException e) {
          return false;
        }
      }

      @Override

            

Reported by PMD.

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

Line: 137

                    public boolean contains(Object object) {
        try {
          return delegate().contains(object);
        } catch (NullPointerException | ClassCastException e) {
          return false;
        }
      }

      @Override

            

Reported by PMD.

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

Line: 144

              
      @Override
      public Iterator<Entry<K, V>> iterator() {
        return delegate().iterator();
      }

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

            

Reported by PMD.

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

Line: 149

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

      @Override
      public boolean remove(Object o) {
        return delegate().remove(o);

            

Reported by PMD.

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class BiMapEntrySetTester<K, V> extends AbstractBiMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testSetValue_valueAbsent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));

            

Reported by PMD.

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

Line: 37

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testSetValue_valueAbsent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));
      }
    }
    expectReplacement(entry(k0(), v3()));

            

Reported by PMD.

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

Line: 38

                @CollectionSize.Require(absent = ZERO)
  public void testSetValue_valueAbsent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));
      }
    }
    expectReplacement(entry(k0(), 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

                  expectReplacement(entry(k0(), v3()));
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(SEVERAL)
  public void testSetValue_valuePresent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        try {

            

Reported by PMD.

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

Line: 48

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(SEVERAL)
  public void testSetValue_valuePresent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        try {
          entry.setValue(v1());
          fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {

            

Reported by PMD.

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

Line: 49

                @CollectionSize.Require(SEVERAL)
  public void testSetValue_valuePresent() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      if (entry.getKey().equals(k0())) {
        try {
          entry.setValue(v1());
          fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException 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: 60

                  expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testSetValueNullUnsupported() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      try {
        entry.setValue(null);

            

Reported by PMD.

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

Line: 63

                @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testSetValueNullUnsupported() {
    for (Entry<K, V> entry : getMap().entrySet()) {
      try {
        entry.setValue(null);
        fail("Expected NullPointerException");
      } catch (NullPointerException expected) {
      }

            

Reported by PMD.

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

Line: 67

                    try {
        entry.setValue(null);
        fail("Expected NullPointerException");
      } catch (NullPointerException expected) {
      }
      expectUnchanged();
    }
  }


            

Reported by PMD.

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

Line: 67

                    try {
        entry.setValue(null);
        fail("Expected NullPointerException");
      } catch (NullPointerException expected) {
      }
      expectUnchanged();
    }
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/TablesTest.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

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

  @GwtIncompatible // SerializableTester
  public void testImmutableEntrySerialization() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    SerializableTester.reserializeAndAssert(entry);
  }


            

Reported by PMD.

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

Line: 35

              public class TablesTest extends TestCase {

  @GwtIncompatible // SerializableTester
  public void testImmutableEntrySerialization() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    SerializableTester.reserializeAndAssert(entry);
  }

  public void testImmutableEntryToString() {

            

Reported by PMD.

The String literal 'foo' appears 7 times in this file; the first occurrence is on line 36
Error

Line: 36

              
  @GwtIncompatible // SerializableTester
  public void testImmutableEntrySerialization() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    SerializableTester.reserializeAndAssert(entry);
  }

  public void testImmutableEntryToString() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');

            

Reported by PMD.

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

Line: 40

                  SerializableTester.reserializeAndAssert(entry);
  }

  public void testImmutableEntryToString() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());

            

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

                  SerializableTester.reserializeAndAssert(entry);
  }

  public void testImmutableEntryToString() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());

            

Reported by PMD.

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

Line: 42

              
  public void testImmutableEntryToString() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

              
  public void testImmutableEntryToString() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');
    assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 45

                  assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());
  }

  public void testEntryEquals() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');


            

Reported by PMD.

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

Line: 45

                  assertEquals("(foo,1)=a", entry.toString());

    Cell<String, Integer, Character> nullEntry = Tables.immutableCell(null, null, null);
    assertEquals("(null,null)=null", nullEntry.toString());
  }

  public void testEntryEquals() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');


            

Reported by PMD.

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

Line: 48

                  assertEquals("(null,null)=null", nullEntry.toString());
  }

  public void testEntryEquals() {
    Cell<String, Integer, Character> entry = Tables.immutableCell("foo", 1, 'a');

    new EqualsTester()
        .addEqualityGroup(entry, Tables.immutableCell("foo", 1, 'a'))
        .addEqualityGroup(Tables.immutableCell("bar", 1, 'a'))

            

Reported by PMD.