The following issues were found

android/guava-tests/test/com/google/common/math/DoubleUtilsTest.java
17 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: 33

               * @author Louis Wasserman
 */
public class DoubleUtilsTest extends TestCase {
  @AndroidIncompatible // no FpUtils and no Math.nextDown in old versions
  public void testNextDown() throws Exception {
    Method jdkNextDown = getJdkNextDown();
    for (double d : FINITE_DOUBLE_CANDIDATES) {
      assertEquals(jdkNextDown.invoke(null, d), DoubleUtils.nextDown(d));
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 37

                public void testNextDown() throws Exception {
    Method jdkNextDown = getJdkNextDown();
    for (double d : FINITE_DOUBLE_CANDIDATES) {
      assertEquals(jdkNextDown.invoke(null, d), DoubleUtils.nextDown(d));
    }
  }

  private static Method getJdkNextDown() throws Exception {
    try {

            

Reported by PMD.

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

Line: 41

                  }
  }

  private static Method getJdkNextDown() throws Exception {
    try {
      return Math.class.getMethod("nextDown", double.class);
    } catch (NoSuchMethodException expectedBeforeJava8) {
      return Class.forName("sun.misc.FpUtils").getMethod("nextDown", double.class);
    }

            

Reported by PMD.

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

Line: 45

                  try {
      return Math.class.getMethod("nextDown", double.class);
    } catch (NoSuchMethodException expectedBeforeJava8) {
      return Class.forName("sun.misc.FpUtils").getMethod("nextDown", double.class);
    }
  }

  @AndroidIncompatible // TODO(cpovirk): File bug for BigDecimal.doubleValue().
  public void testBigToDouble() {

            

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

                  }
  }

  @AndroidIncompatible // TODO(cpovirk): File bug for BigDecimal.doubleValue().
  public void testBigToDouble() {
    for (BigInteger b : ALL_BIGINTEGER_CANDIDATES) {
      if (b.doubleValue() != DoubleUtils.bigToDouble(b)) {
        failFormat(
            "Converting %s to double: expected doubleValue %s but got bigToDouble %s",

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 52

                @AndroidIncompatible // TODO(cpovirk): File bug for BigDecimal.doubleValue().
  public void testBigToDouble() {
    for (BigInteger b : ALL_BIGINTEGER_CANDIDATES) {
      if (b.doubleValue() != DoubleUtils.bigToDouble(b)) {
        failFormat(
            "Converting %s to double: expected doubleValue %s but got bigToDouble %s",
            b, b.doubleValue(), DoubleUtils.bigToDouble(b));
      }
    }

            

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

                  }
  }

  public void testEnsureNonNegative() {
    assertEquals(0.0, DoubleUtils.ensureNonNegative(0.0));
    for (double positiveValue : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
      assertEquals(positiveValue, DoubleUtils.ensureNonNegative(positiveValue));
      assertEquals(0.0, DoubleUtils.ensureNonNegative(-positiveValue));
    }

            

Reported by PMD.

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

Line: 60

                  }
  }

  public void testEnsureNonNegative() {
    assertEquals(0.0, DoubleUtils.ensureNonNegative(0.0));
    for (double positiveValue : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
      assertEquals(positiveValue, DoubleUtils.ensureNonNegative(positiveValue));
      assertEquals(0.0, DoubleUtils.ensureNonNegative(-positiveValue));
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                }

  public void testEnsureNonNegative() {
    assertEquals(0.0, DoubleUtils.ensureNonNegative(0.0));
    for (double positiveValue : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
      assertEquals(positiveValue, DoubleUtils.ensureNonNegative(positiveValue));
      assertEquals(0.0, DoubleUtils.ensureNonNegative(-positiveValue));
    }
    assertEquals(Double.POSITIVE_INFINITY, DoubleUtils.ensureNonNegative(Double.POSITIVE_INFINITY));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

                public void testEnsureNonNegative() {
    assertEquals(0.0, DoubleUtils.ensureNonNegative(0.0));
    for (double positiveValue : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
      assertEquals(positiveValue, DoubleUtils.ensureNonNegative(positiveValue));
      assertEquals(0.0, DoubleUtils.ensureNonNegative(-positiveValue));
    }
    assertEquals(Double.POSITIVE_INFINITY, DoubleUtils.ensureNonNegative(Double.POSITIVE_INFINITY));
    assertEquals(0.0, DoubleUtils.ensureNonNegative(Double.NEGATIVE_INFINITY));
    try {

            

Reported by PMD.

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

Line: 48

                 */
  final <T> T newProxy(TypeToken<T> interfaceType) {
    Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
    interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
    // Make the proxy serializable to work with SerializableTester
    interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),

            

Reported by PMD.

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

Line: 48

                 */
  final <T> T newProxy(TypeToken<T> interfaceType) {
    Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
    interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
    // Make the proxy serializable to work with SerializableTester
    interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),

            

Reported by PMD.

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

Line: 48

                 */
  final <T> T newProxy(TypeToken<T> interfaceType) {
    Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
    interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
    // Make the proxy serializable to work with SerializableTester
    interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),

            

Reported by PMD.

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

Line: 50

                  Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
    interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
    // Make the proxy serializable to work with SerializableTester
    interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));

            

Reported by PMD.

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

Line: 53

                  interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;

            

Reported by PMD.

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

Line: 53

                  interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;

            

Reported by PMD.

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

Line: 53

                  interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 53

                  interfaceClasses.add(Serializable.class);
    Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;

            

Reported by PMD.

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

Line: 54

                  Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;
  }

            

Reported by PMD.

This call to Collection.toArray() may be optimizable
Performance

Line: 54

                  Object dummy =
        Proxy.newProxyInstance(
            interfaceClasses.iterator().next().getClassLoader(),
            interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
            new DummyHandler(interfaceType));
    @SuppressWarnings("unchecked") // interfaceType is T
    T result = (T) dummy;
    return result;
  }

            

Reported by PMD.

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

Line: 50

                 * there's no problem. The reason: {@link EqualsTester} tests {@code null} and identical inputs
   * directly against {@code equals()} rather than through the {@code Equivalence}.
   */
  private final Equivalence<? super T> equivalence;

  private final String relationshipName;
  private final String hashName;
  private final ItemReporter itemReporter;
  private final List<ImmutableList<T>> groups = Lists.newArrayList();

            

Reported by PMD.

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

Line: 52

                 */
  private final Equivalence<? super T> equivalence;

  private final String relationshipName;
  private final String hashName;
  private final ItemReporter itemReporter;
  private final List<ImmutableList<T>> groups = Lists.newArrayList();

  RelationshipTester(

            

Reported by PMD.

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

Line: 53

                private final Equivalence<? super T> equivalence;

  private final String relationshipName;
  private final String hashName;
  private final ItemReporter itemReporter;
  private final List<ImmutableList<T>> groups = Lists.newArrayList();

  RelationshipTester(
      Equivalence<? super T> equivalence,

            

Reported by PMD.

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

Line: 54

              
  private final String relationshipName;
  private final String hashName;
  private final ItemReporter itemReporter;
  private final List<ImmutableList<T>> groups = Lists.newArrayList();

  RelationshipTester(
      Equivalence<? super T> equivalence,
      String relationshipName,

            

Reported by PMD.

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

Line: 55

                private final String relationshipName;
  private final String hashName;
  private final ItemReporter itemReporter;
  private final List<ImmutableList<T>> groups = Lists.newArrayList();

  RelationshipTester(
      Equivalence<? super T> equivalence,
      String relationshipName,
      String hashName,

            

Reported by PMD.

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

Line: 74

                  return this;
  }

  public void test() {
    for (int groupNumber = 0; groupNumber < groups.size(); groupNumber++) {
      ImmutableList<T> group = groups.get(groupNumber);
      for (int itemNumber = 0; itemNumber < group.size(); itemNumber++) {
        // check related items in same group
        for (int relatedItemNumber = 0; relatedItemNumber < group.size(); relatedItemNumber++) {

            

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

                  return this;
  }

  public void test() {
    for (int groupNumber = 0; groupNumber < groups.size(); groupNumber++) {
      ImmutableList<T> group = groups.get(groupNumber);
      for (int itemNumber = 0; itemNumber < group.size(); itemNumber++) {
        // check related items in same group
        for (int relatedItemNumber = 0; relatedItemNumber < group.size(); relatedItemNumber++) {

            

Reported by PMD.

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

Line: 77

                public void test() {
    for (int groupNumber = 0; groupNumber < groups.size(); groupNumber++) {
      ImmutableList<T> group = groups.get(groupNumber);
      for (int itemNumber = 0; itemNumber < group.size(); itemNumber++) {
        // check related items in same group
        for (int relatedItemNumber = 0; relatedItemNumber < group.size(); relatedItemNumber++) {
          if (itemNumber != relatedItemNumber) {
            assertRelated(groupNumber, itemNumber, relatedItemNumber);
          }

            

Reported by PMD.

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

Line: 79

                    ImmutableList<T> group = groups.get(groupNumber);
      for (int itemNumber = 0; itemNumber < group.size(); itemNumber++) {
        // check related items in same group
        for (int relatedItemNumber = 0; relatedItemNumber < group.size(); relatedItemNumber++) {
          if (itemNumber != relatedItemNumber) {
            assertRelated(groupNumber, itemNumber, relatedItemNumber);
          }
        }
        // check unrelated items in all other groups

            

Reported by PMD.

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

Line: 91

                        if (groupNumber != unrelatedGroupNumber) {
            ImmutableList<T> unrelatedGroup = groups.get(unrelatedGroupNumber);
            for (int unrelatedItemNumber = 0;
                unrelatedItemNumber < unrelatedGroup.size();
                unrelatedItemNumber++) {
              assertUnrelated(groupNumber, itemNumber, unrelatedGroupNumber, unrelatedItemNumber);
            }
          }
        }

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java
17 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 39

              import junit.framework.TestSuite;

public class SafeTreeSetTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SafeTreeSetTest.class);
    suite.addTest(
        NavigableSetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

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

Line: 66

                              new TestStringSetGenerator() {
                  @Override
                  protected Set<String> create(String[] elements) {
                    NavigableSet<String> set = new SafeTreeSet<>(Ordering.natural().nullsFirst());
                    Collections.addAll(set, elements);
                    return set;
                  }

                  @Override

            

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

                  return suite;
  }

  @GwtIncompatible // SerializableTester
  public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(

            

Reported by PMD.

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

Line: 89

                @GwtIncompatible // SerializableTester
  public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

            

Reported by PMD.

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

Line: 90

                public void testViewSerialization() {
    Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 91

                  Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
    SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester

            

Reported by PMD.

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

Line: 92

                  SerializableTester.reserializeAndAssert(map.entrySet());
    SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester
  public void testEmpty_serialization() {

            

Reported by PMD.

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

Line: 93

                  SerializableTester.reserializeAndAssert(map.keySet());
    assertEquals(
        Lists.newArrayList(map.values()),
        Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester
  public void testEmpty_serialization() {
    SortedSet<String> set = new SafeTreeSet<>();

            

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

                      Lists.newArrayList(SerializableTester.reserialize(map.values())));
  }

  @GwtIncompatible // SerializableTester
  public void testEmpty_serialization() {
    SortedSet<String> set = new SafeTreeSet<>();
    SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
    assertEquals(set.comparator(), copy.comparator());
  }

            

Reported by PMD.

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

Line: 100

                public void testEmpty_serialization() {
    SortedSet<String> set = new SafeTreeSet<>();
    SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
    assertEquals(set.comparator(), copy.comparator());
  }

  @GwtIncompatible // SerializableTester
  public void testSingle_serialization() {
    SortedSet<String> set = new SafeTreeSet<>();

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java
17 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: 48

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapCreationTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testCreateWithNullKeySupported() {
    initMapWithNullKey();
    expectContents(createArrayWithNullKey());
  }

            

Reported by PMD.

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

Line: 55

                  expectContents(createArrayWithNullKey());
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testCreateWithNullKeyUnsupported() {
    try {
      initMapWithNullKey();
      fail("Creating a map containing a null key should fail");

            

Reported by PMD.

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

Line: 61

                  try {
      initMapWithNullKey();
      fail("Creating a map containing a null key should fail");
    } catch (NullPointerException expected) {
    }
  }

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

            

Reported by PMD.

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

Line: 61

                  try {
      initMapWithNullKey();
      fail("Creating a map containing a null key should fail");
    } catch (NullPointerException expected) {
    }
  }

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

                  }
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testCreateWithNullValueSupported() {
    initMapWithNullValue();
    expectContents(createArrayWithNullValue());
  }

            

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

                  expectContents(createArrayWithNullValue());
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testCreateWithNullValueUnsupported() {
    try {
      initMapWithNullValue();
      fail("Creating a map containing a null value should fail");

            

Reported by PMD.

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

Line: 78

                  try {
      initMapWithNullValue();
      fail("Creating a map containing a null value should fail");
    } catch (NullPointerException expected) {
    }
  }

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

            

Reported by PMD.

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

Line: 78

                  try {
      initMapWithNullValue();
      fail("Creating a map containing a null value should fail");
    } catch (NullPointerException expected) {
    }
  }

  @MapFeature.Require({ALLOWS_NULL_KEYS, 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: 82

                  }
  }

  @MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testCreateWithNullKeyAndValueSupported() {
    Entry<K, V>[] entries = createSamplesArray();
    entries[getNullLocation()] = entry(null, null);
    resetMap(entries);

            

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

                  expectContents(entries);
  }

  @MapFeature.Require(value = ALLOWS_NULL_KEYS, absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
    expectFirstRemoved(getEntriesMultipleNullKeys());
  }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java
17 issues
Class cannot be instantiated and does not provide any static methods or fields
Error

Line: 42

               * @author Louis Wasserman
 */
@GwtCompatible
public final class DerivedGoogleCollectionGenerators {
  public static class MapGenerator<K, V> implements TestMapGenerator<K, V>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public MapGenerator(

            

Reported by PMD.

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

Line: 45

              public final class DerivedGoogleCollectionGenerators {
  public static class MapGenerator<K, V> implements TestMapGenerator<K, V>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public MapGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
      this.generator = oneSizeTestContainerGenerator;
    }

            

Reported by PMD.

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

Line: 72

                    return generator.order(insertionOrder);
    }

    @SuppressWarnings("unchecked")
    @Override
    public K[] createKeyArray(int length) {
      return (K[]) new Object[length];
    }


            

Reported by PMD.

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

Line: 93

                public static class InverseBiMapGenerator<K, V>
      implements TestBiMapGenerator<V, K>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public InverseBiMapGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
      this.generator = oneSizeTestContainerGenerator;
    }

            

Reported by PMD.

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

Line: 104

                  public SampleElements<Entry<V, K>> samples() {
      SampleElements<Entry<K, V>> samples = generator.samples();
      return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

            

Reported by PMD.

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

Line: 105

                    SampleElements<Entry<K, V>> samples = generator.samples();
      return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }


            

Reported by PMD.

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

Line: 106

                    return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {

            

Reported by PMD.

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

Line: 107

                        reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {
      return Helpers.mapEntry(entry.getValue(), entry.getKey());

            

Reported by PMD.

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

Line: 108

                        reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {
      return Helpers.mapEntry(entry.getValue(), entry.getKey());
    }

            

Reported by PMD.

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

Line: 156

              
  public static class BiMapValueSetGenerator<K, V>
      implements TestSetGenerator<V>, DerivedGenerator {
    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator;
    private final SampleElements<V> samples;

    public BiMapValueSetGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator) {
      this.mapGenerator = mapGenerator;

            

Reported by PMD.

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

Line: 42

              
  @Override
  protected void assertGet(K key, Collection<V> values) {
    assertEqualInOrder(values, multimap().get(key));

    if (!values.isEmpty()) {
      assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {

            

Reported by PMD.

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

Line: 45

                  assertEqualInOrder(values, multimap().get(key));

    if (!values.isEmpty()) {
      assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {
      assertNull(multimap().asMap().get(key));
    }


            

Reported by PMD.

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

Line: 45

                  assertEqualInOrder(values, multimap().get(key));

    if (!values.isEmpty()) {
      assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {
      assertNull(multimap().asMap().get(key));
    }


            

Reported by PMD.

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

Line: 46

              
    if (!values.isEmpty()) {
      assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {
      assertNull(multimap().asMap().get(key));
    }

    assertEquals(values.size(), multimap().get(key).size());

            

Reported by PMD.

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

Line: 48

                    assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {
      assertNull(multimap().asMap().get(key));
    }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));

            

Reported by PMD.

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

Line: 48

                    assertEqualInOrder(values, multimap().asMap().get(key));
      assertFalse(multimap().isEmpty());
    } else {
      assertNull(multimap().asMap().get(key));
    }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));

            

Reported by PMD.

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

Line: 51

                    assertNull(multimap().asMap().get(key));
    }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));
    assertEquals(values.size() > 0, multimap().keys().contains(key));
  }
}

            

Reported by PMD.

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

Line: 51

                    assertNull(multimap().asMap().get(key));
    }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));
    assertEquals(values.size() > 0, multimap().keys().contains(key));
  }
}

            

Reported by PMD.

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

Line: 52

                  }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));
    assertEquals(values.size() > 0, multimap().keys().contains(key));
  }
}

            

Reported by PMD.

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

Line: 52

                  }

    assertEquals(values.size(), multimap().get(key).size());
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));
    assertEquals(values.size() > 0, multimap().keys().contains(key));
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/testing/GcFinalization.java
16 issues
Avoid throwing raw exception types.
Design

Line: 155

                    } catch (CancellationException | ExecutionException ok) {
        return;
      } catch (InterruptedException ie) {
        throw new RuntimeException("Unexpected interrupt while waiting for future", ie);
      } catch (TimeoutException tryHarder) {
        /* OK */
      }
    } while (System.nanoTime() - deadline < 0);
    throw formatRuntimeException("Future not done within %d second timeout", timeoutSeconds);

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 214

                        return;
        }
      } catch (InterruptedException ie) {
        throw new RuntimeException("Unexpected interrupt while waiting for latch", ie);
      }
    } while (System.nanoTime() - deadline < 0);
    throw formatRuntimeException(
        "Latch failed to count down within %d second timeout", timeoutSeconds);
  }

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 144

                  final long timeoutSeconds = timeoutSeconds();
    final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
    do {
      System.runFinalization();
      if (future.isDone()) {
        return;
      }
      System.gc();
      try {

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 148

                    if (future.isDone()) {
        return;
      }
      System.gc();
      try {
        future.get(1L, SECONDS);
        return;
      } catch (CancellationException | ExecutionException ok) {
        return;

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 176

                  final long timeoutSeconds = timeoutSeconds();
    final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
    do {
      System.runFinalization();
      if (predicate.isDone()) {
        return;
      }
      CountDownLatch done = new CountDownLatch(1);
      createUnreachableLatchFinalizer(done);

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 204

                  final long timeoutSeconds = timeoutSeconds();
    final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
    do {
      System.runFinalization();
      if (latch.getCount() == 0) {
        return;
      }
      System.gc();
      try {

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 208

                    if (latch.getCount() == 0) {
        return;
      }
      System.gc();
      try {
        if (latch.await(1L, SECONDS)) {
          return;
        }
      } catch (InterruptedException ie) {

            

Reported by PMD.

Do not explicitly trigger a garbage collection.
Error

Line: 313

                  awaitClear(ref);

    // Hope to catch some stragglers queued up behind our finalizable object
    System.runFinalization();
  }

  private static RuntimeException formatRuntimeException(String format, Object... args) {
    return new RuntimeException(String.format(Locale.ROOT, format, args));
  }

            

Reported by PMD.

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

Line: 128

                  //
    // TODO(user): Consider scaling by number of mutator threads,
    // e.g. using Thread#activeCount()
    return Math.max(10L, Runtime.getRuntime().totalMemory() / (32L * 1024L * 1024L));
  }

  /**
   * Waits until the given future {@linkplain Future#isDone is done}, invoking the garbage collector
   * as necessary to try to ensure that this will happen.

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 156

                      return;
      } catch (InterruptedException ie) {
        throw new RuntimeException("Unexpected interrupt while waiting for future", ie);
      } catch (TimeoutException tryHarder) {
        /* OK */
      }
    } while (System.nanoTime() - deadline < 0);
    throw formatRuntimeException("Future not done within %d second timeout", timeoutSeconds);
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java
16 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: 30

               */
public class ChecksumHashFunctionTest extends TestCase {

  public void testCrc32_equalsChecksumValue() throws Exception {
    assertChecksum(CRC_32, "");
    assertChecksum(CRC_32, "Z");
    assertChecksum(CRC_32, "foobar");
  }


            

Reported by PMD.

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

Line: 30

               */
public class ChecksumHashFunctionTest extends TestCase {

  public void testCrc32_equalsChecksumValue() throws Exception {
    assertChecksum(CRC_32, "");
    assertChecksum(CRC_32, "Z");
    assertChecksum(CRC_32, "foobar");
  }


            

Reported by PMD.

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

Line: 36

                  assertChecksum(CRC_32, "foobar");
  }

  public void testAdler32_equalsChecksumValue() throws Exception {
    assertChecksum(ADLER_32, "");
    assertChecksum(ADLER_32, "Z");
    assertChecksum(ADLER_32, "foobar");
  }


            

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

                  assertChecksum(CRC_32, "foobar");
  }

  public void testAdler32_equalsChecksumValue() throws Exception {
    assertChecksum(ADLER_32, "");
    assertChecksum(ADLER_32, "Z");
    assertChecksum(ADLER_32, "foobar");
  }


            

Reported by PMD.

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

Line: 42

                  assertChecksum(ADLER_32, "foobar");
  }

  public void testCrc32_knownValues() throws Exception {
    assertHash32(0x1C8600E3, CRC_32, "hell");
    assertHash32(0x3610A686, CRC_32, "hello");
    assertHash32(0xED81F9F6, CRC_32, "hello ");
    assertHash32(0x4850DDC2, CRC_32, "hello w");
    assertHash32(0x7A2D6005, CRC_32, "hello wo");

            

Reported by PMD.

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

Line: 42

                  assertChecksum(ADLER_32, "foobar");
  }

  public void testCrc32_knownValues() throws Exception {
    assertHash32(0x1C8600E3, CRC_32, "hell");
    assertHash32(0x3610A686, CRC_32, "hello");
    assertHash32(0xED81F9F6, CRC_32, "hello ");
    assertHash32(0x4850DDC2, CRC_32, "hello w");
    assertHash32(0x7A2D6005, CRC_32, "hello wo");

            

Reported by PMD.

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

Line: 53

                  assertHash32(0x4400B5BC, CRC_32, "The quick brown fox jumps over the lazy cog");
  }

  public void testAdler32_knownValues() throws Exception {
    assertHash32(0x041701A6, ADLER_32, "hell");
    assertHash32(0x062C0215, ADLER_32, "hello");
    assertHash32(0x08610235, ADLER_32, "hello ");
    assertHash32(0x0B0D02AC, ADLER_32, "hello w");
    assertHash32(0x0E28031B, ADLER_32, "hello wo");

            

Reported by PMD.

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

Line: 53

                  assertHash32(0x4400B5BC, CRC_32, "The quick brown fox jumps over the lazy cog");
  }

  public void testAdler32_knownValues() throws Exception {
    assertHash32(0x041701A6, ADLER_32, "hell");
    assertHash32(0x062C0215, ADLER_32, "hello");
    assertHash32(0x08610235, ADLER_32, "hello ");
    assertHash32(0x0B0D02AC, ADLER_32, "hello w");
    assertHash32(0x0E28031B, ADLER_32, "hello wo");

            

Reported by PMD.

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

Line: 68

                  byte[] bytes = HashTestUtils.ascii(input);

    Checksum checksum = supplier.get();
    checksum.update(bytes, 0, bytes.length);
    long value = checksum.getValue();

    String toString = "name";
    HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
    assertEquals(toString, func.toString());

            

Reported by PMD.

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

Line: 69

              
    Checksum checksum = supplier.get();
    checksum.update(bytes, 0, bytes.length);
    long value = checksum.getValue();

    String toString = "name";
    HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
    assertEquals(toString, func.toString());
    assertEquals(value, func.hashBytes(bytes).padToLong());

            

Reported by PMD.

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

Line: 50

               * @author Louis Wasserman
 */
public class ForwardingNavigableMapTest extends TestCase {
  static class StandardImplForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
    private final NavigableMap<K, V> backingMap;

    StandardImplForwardingNavigableMap(NavigableMap<K, V> backingMap) {
      this.backingMap = backingMap;
    }

            

Reported by PMD.

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

Line: 51

               */
public class ForwardingNavigableMapTest extends TestCase {
  static class StandardImplForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
    private final NavigableMap<K, V> backingMap;

    StandardImplForwardingNavigableMap(NavigableMap<K, V> backingMap) {
      this.backingMap = backingMap;
    }


            

Reported by PMD.

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

Line: 116

                    return new StandardEntrySet() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
          return backingMap.entrySet().iterator();
        }
      };
    }

    @Override

            

Reported by PMD.

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

Line: 233

                }

  static class StandardLastEntryForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
    private final NavigableMap<K, V> backingMap;

    StandardLastEntryForwardingNavigableMap(NavigableMap<K, V> backingMap) {
      this.backingMap = backingMap;
    }


            

Reported by PMD.

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

Line: 250

                  }
  }

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

    suite.addTestSuite(ForwardingNavigableMapTest.class);
    suite.addTest(
        NavigableMapTestSuiteBuilder.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: 291

                  return suite;
  }

  public void testStandardLastEntry() {
    NavigableMap<String, Integer> forwarding =
        new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
    assertNull(forwarding.lastEntry());
    forwarding.put("b", 2);
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());

            

Reported by PMD.

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

Line: 291

                  return suite;
  }

  public void testStandardLastEntry() {
    NavigableMap<String, Integer> forwarding =
        new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
    assertNull(forwarding.lastEntry());
    forwarding.put("b", 2);
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 294

                public void testStandardLastEntry() {
    NavigableMap<String, Integer> forwarding =
        new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
    assertNull(forwarding.lastEntry());
    forwarding.put("b", 2);
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
    forwarding.put("c", 3);
    assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
    forwarding.put("a", 1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 296

                      new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
    assertNull(forwarding.lastEntry());
    forwarding.put("b", 2);
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
    forwarding.put("c", 3);
    assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
    forwarding.put("a", 1);
    assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
    forwarding.remove("c");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 298

                  forwarding.put("b", 2);
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
    forwarding.put("c", 3);
    assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
    forwarding.put("a", 1);
    assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
    forwarding.remove("c");
    assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
  }

            

Reported by PMD.