The following issues were found

guava-testlib/src/com/google/common/testing/DummyProxy.java
17 issues
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: 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.

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 (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.

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.

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.

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.

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.

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

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.

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

Line: 28

              /** Benchmarks for the hashing of UTF-8 strings. */
public class HashStringBenchmark {
  static class MaxCodePoint {
    final int value;

    /**
     * Convert the input string to a code point. Accepts regular decimal numerals, hex strings, and
     * some symbolic names meaningful to humans.
     */

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 58

                        // Mostly 4-byte UTF-8 sequences - "rare exotic" text
          return Character.MAX_CODE_POINT;
        } else {
          throw new IllegalArgumentException("Can't decode codepoint " + userFriendly);
        }
      }
    }

    public static MaxCodePoint valueOf(String userFriendly) {

            

Reported by PMD.

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

Line: 79

                 * @see MaxCodePoint#decode
   */
  @Param({"0x80", "0x90", "0x100", "0x800", "0x10000", "0x10ffff"})
  MaxCodePoint maxCodePoint;

  @Param({"16384"})
  int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})

            

Reported by PMD.

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

Line: 82

                MaxCodePoint maxCodePoint;

  @Param({"16384"})
  int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

            

Reported by PMD.

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

Line: 85

                int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

  static final int SAMPLES = 0x100;
  static final int SAMPLE_MASK = 0xFF;

            

Reported by PMD.

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

Line: 87

                @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

  static final int SAMPLES = 0x100;
  static final int SAMPLE_MASK = 0xFF;

  /**

            

Reported by PMD.

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

Line: 96

                 * Compute arrays of valid unicode text, and store it in 3 forms: byte arrays, Strings, and
   * StringBuilders (in a CharSequence[] to make it a little harder for the JVM).
   */
  @BeforeExperiment
  void setUp() {
    final long seed = 99;
    final Random rnd = new Random(seed);
    strings = new String[SAMPLES];
    for (int i = 0; i < SAMPLES; i++) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 102

                  final Random rnd = new Random(seed);
    strings = new String[SAMPLES];
    for (int i = 0; i < SAMPLES; i++) {
      StringBuilder sb = new StringBuilder();
      for (int j = 0; j < charCount; j++) {
        int codePoint;
        // discard illegal surrogate "codepoints"
        do {
          codePoint = rnd.nextInt(maxCodePoint.value);

            

Reported by PMD.

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

Line: 121

                  for (int i = 0; i < reps; i++) {
      res +=
          System.identityHashCode(
              hashFunctionEnum
                  .getHashFunction()
                  .hashString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8));
    }
    return res;
  }

            

Reported by PMD.

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

Line: 134

                  for (int i = 0; i < reps; i++) {
      res +=
          System.identityHashCode(
              hashFunctionEnum
                  .getHashFunction()
                  .newHasher()
                  .putString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8)
                  .hash());
    }

            

Reported by PMD.

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

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.

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.

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

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

            

Reported by PMD.

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

Line: 40

              public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 40

              public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 42

                public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {

            

Reported by PMD.

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

Line: 42

                public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {

            

Reported by PMD.

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

Line: 46

                  }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

            

Reported by PMD.

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

Line: 47

                }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 48

              
  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)

            

Reported by PMD.

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

Line: 48

              
  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)

            

Reported by PMD.

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

Line: 49

                public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testAsMapRemoveImplementsSortedSet() {

            

Reported by PMD.

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

Line: 28

              /** Benchmarks for the hashing of UTF-8 strings. */
public class HashStringBenchmark {
  static class MaxCodePoint {
    final int value;

    /**
     * Convert the input string to a code point. Accepts regular decimal numerals, hex strings, and
     * some symbolic names meaningful to humans.
     */

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 58

                        // Mostly 4-byte UTF-8 sequences - "rare exotic" text
          return Character.MAX_CODE_POINT;
        } else {
          throw new IllegalArgumentException("Can't decode codepoint " + userFriendly);
        }
      }
    }

    public static MaxCodePoint valueOf(String userFriendly) {

            

Reported by PMD.

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

Line: 79

                 * @see MaxCodePoint#decode
   */
  @Param({"0x80", "0x90", "0x100", "0x800", "0x10000", "0x10ffff"})
  MaxCodePoint maxCodePoint;

  @Param({"16384"})
  int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})

            

Reported by PMD.

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

Line: 82

                MaxCodePoint maxCodePoint;

  @Param({"16384"})
  int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

            

Reported by PMD.

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

Line: 85

                int charCount;

  @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

  static final int SAMPLES = 0x100;
  static final int SAMPLE_MASK = 0xFF;

            

Reported by PMD.

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

Line: 87

                @Param({"MURMUR3_32", "MURMUR3_128", "SHA1"})
  HashFunctionEnum hashFunctionEnum;

  private String[] strings;

  static final int SAMPLES = 0x100;
  static final int SAMPLE_MASK = 0xFF;

  /**

            

Reported by PMD.

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

Line: 96

                 * Compute arrays of valid unicode text, and store it in 3 forms: byte arrays, Strings, and
   * StringBuilders (in a CharSequence[] to make it a little harder for the JVM).
   */
  @BeforeExperiment
  void setUp() {
    final long seed = 99;
    final Random rnd = new Random(seed);
    strings = new String[SAMPLES];
    for (int i = 0; i < SAMPLES; i++) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 102

                  final Random rnd = new Random(seed);
    strings = new String[SAMPLES];
    for (int i = 0; i < SAMPLES; i++) {
      StringBuilder sb = new StringBuilder();
      for (int j = 0; j < charCount; j++) {
        int codePoint;
        // discard illegal surrogate "codepoints"
        do {
          codePoint = rnd.nextInt(maxCodePoint.value);

            

Reported by PMD.

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

Line: 121

                  for (int i = 0; i < reps; i++) {
      res +=
          System.identityHashCode(
              hashFunctionEnum
                  .getHashFunction()
                  .hashString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8));
    }
    return res;
  }

            

Reported by PMD.

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

Line: 134

                  for (int i = 0; i < reps; i++) {
      res +=
          System.identityHashCode(
              hashFunctionEnum
                  .getHashFunction()
                  .newHasher()
                  .putString(strings[i & SAMPLE_MASK], StandardCharsets.UTF_8)
                  .hash());
    }

            

Reported by PMD.

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

Line: 39

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper

            

Reported by PMD.

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

Line: 40

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 41

              public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 43

                protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  public void setUp() throws Exception {
    super.setUp();
    samples = this.getSubjectGenerator().samples();
    resetContainer();

            

Reported by PMD.

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

Line: 65

                 * @return the new container instance.
   */
  protected C resetContainer() {
    return resetContainer(getSubjectGenerator().createTestSubject());
  }

  /**
   * Replaces the existing container under test with a new container. This is useful when a single
   * test method needs to create multiple containers while retaining the ability to use {@link

            

Reported by PMD.

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

Line: 136

                 */
  protected final void expectAdded(E... elements) {
    List<E> expected = Helpers.copyToList(getSampleElements());
    expected.addAll(Arrays.asList(elements));
    expectContents(expected);
  }

  protected final void expectAdded(int index, E... elements) {
    expectAdded(index, Arrays.asList(elements));

            

Reported by PMD.

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

Line: 146

              
  protected final void expectAdded(int index, Collection<E> elements) {
    List<E> expected = Helpers.copyToList(getSampleElements());
    expected.addAll(index, elements);
    expectContents(expected);
  }

  /*
   * TODO: if we're testing a list, we could check indexOf(). (Doing it in

            

Reported by PMD.

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

Line: 158

                 */
  protected void expectMissing(E... elements) {
    for (E element : elements) {
      assertFalse("Should not contain " + element, actualContents().contains(element));
    }
  }

  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());

            

Reported by PMD.

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

Line: 163

                }

  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());
    getSampleElements().toArray(array);
    return array;
  }

  protected E[] createOrderedArray() {

            

Reported by PMD.

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

Line: 164

              
  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());
    getSampleElements().toArray(array);
    return array;
  }

  protected E[] createOrderedArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());

            

Reported by PMD.

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

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

            

Reported by PMD.

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

Line: 40

              public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 40

              public class SortedSetMultimapAsMapTester<K, V>
    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
  public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 42

                public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {

            

Reported by PMD.

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

Line: 42

                public void testAsMapValuesImplementSortedSet() {
    for (Collection<V> valueCollection : multimap().asMap().values()) {
      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {

            

Reported by PMD.

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

Line: 46

                  }
  }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

            

Reported by PMD.

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

Line: 47

                }

  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }


            

Reported by PMD.

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

Line: 48

              
  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)

            

Reported by PMD.

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

Line: 48

              
  public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)

            

Reported by PMD.

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

Line: 49

                public void testAsMapGetImplementsSortedSet() {
    for (K key : multimap().keySet()) {
      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
      assertEquals(multimap().valueComparator(), valueSet.comparator());
    }
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testAsMapRemoveImplementsSortedSet() {

            

Reported by PMD.