The following issues were found

android/guava/src/com/google/common/primitives/UnsignedLong.java
8 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 42

               */
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedLong extends Number implements Comparable<UnsignedLong>, Serializable {

  private static final long UNSIGNED_MASK = 0x7fffffffffffffffL;

  public static final UnsignedLong ZERO = new UnsignedLong(0);
  public static final UnsignedLong ONE = new UnsignedLong(1);

            

Reported by PMD.

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

Line: 42

               */
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedLong extends Number implements Comparable<UnsignedLong>, Serializable {

  private static final long UNSIGNED_MASK = 0x7fffffffffffffffL;

  public static final UnsignedLong ZERO = new UnsignedLong(0);
  public static final UnsignedLong ONE = new UnsignedLong(1);

            

Reported by PMD.

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

Line: 50

                public static final UnsignedLong ONE = new UnsignedLong(1);
  public static final UnsignedLong MAX_VALUE = new UnsignedLong(-1L);

  private final long value;

  private UnsignedLong(long value) {
    this.value = value;
  }


            

Reported by PMD.

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

Line: 134

                 * @since 14.0
   */
  public UnsignedLong plus(UnsignedLong val) {
    return fromLongBits(this.value + checkNotNull(val).value);
  }

  /**
   * Returns the result of subtracting this and {@code val}. If the result would have more than 64
   * bits, returns the low 64 bits of the result.

            

Reported by PMD.

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

Line: 144

                 * @since 14.0
   */
  public UnsignedLong minus(UnsignedLong val) {
    return fromLongBits(this.value - checkNotNull(val).value);
  }

  /**
   * Returns the result of multiplying this and {@code val}. If the result would have more than 64
   * bits, returns the low 64 bits of the result.

            

Reported by PMD.

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

Line: 154

                 * @since 14.0
   */
  public UnsignedLong times(UnsignedLong val) {
    return fromLongBits(value * checkNotNull(val).value);
  }

  /**
   * Returns the result of dividing this by {@code val}.
   *

            

Reported by PMD.

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

Line: 163

                 * @since 14.0
   */
  public UnsignedLong dividedBy(UnsignedLong val) {
    return fromLongBits(UnsignedLongs.divide(value, checkNotNull(val).value));
  }

  /**
   * Returns this modulo {@code val}.
   *

            

Reported by PMD.

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

Line: 172

                 * @since 14.0
   */
  public UnsignedLong mod(UnsignedLong val) {
    return fromLongBits(UnsignedLongs.remainder(value, checkNotNull(val).value));
  }

  /** Returns the value of this {@code UnsignedLong} as an {@code int}. */
  @Override
  public int intValue() {

            

Reported by PMD.

android/guava/src/com/google/common/primitives/UnsignedInteger.java
8 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 43

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> {
  public static final UnsignedInteger ZERO = fromIntBits(0);
  public static final UnsignedInteger ONE = fromIntBits(1);
  public static final UnsignedInteger MAX_VALUE = fromIntBits(-1);

  private final int value;

            

Reported by PMD.

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

Line: 43

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> {
  public static final UnsignedInteger ZERO = fromIntBits(0);
  public static final UnsignedInteger ONE = fromIntBits(1);
  public static final UnsignedInteger MAX_VALUE = fromIntBits(-1);

  private final int value;

            

Reported by PMD.

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

Line: 48

                public static final UnsignedInteger ONE = fromIntBits(1);
  public static final UnsignedInteger MAX_VALUE = fromIntBits(-1);

  private final int value;

  private UnsignedInteger(int value) {
    // GWT doesn't consistently overflow values to make them 32-bit, so we need to force it.
    this.value = value & 0xffffffff;
  }

            

Reported by PMD.

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

Line: 127

                 * @since 14.0
   */
  public UnsignedInteger plus(UnsignedInteger val) {
    return fromIntBits(this.value + checkNotNull(val).value);
  }

  /**
   * Returns the result of subtracting this and {@code val}. If the result would be negative,
   * returns the low 32 bits of the result.

            

Reported by PMD.

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

Line: 137

                 * @since 14.0
   */
  public UnsignedInteger minus(UnsignedInteger val) {
    return fromIntBits(value - checkNotNull(val).value);
  }

  /**
   * Returns the result of multiplying this and {@code val}. If the result would have more than 32
   * bits, returns the low 32 bits of the result.

            

Reported by PMD.

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

Line: 149

                @GwtIncompatible // Does not truncate correctly
  public UnsignedInteger times(UnsignedInteger val) {
    // TODO(lowasser): make this GWT-compatible
    return fromIntBits(value * checkNotNull(val).value);
  }

  /**
   * Returns the result of dividing this by {@code val}.
   *

            

Reported by PMD.

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

Line: 159

                 * @since 14.0
   */
  public UnsignedInteger dividedBy(UnsignedInteger val) {
    return fromIntBits(UnsignedInts.divide(value, checkNotNull(val).value));
  }

  /**
   * Returns this mod {@code val}.
   *

            

Reported by PMD.

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

Line: 169

                 * @since 14.0
   */
  public UnsignedInteger mod(UnsignedInteger val) {
    return fromIntBits(UnsignedInts.remainder(value, checkNotNull(val).value));
  }

  /**
   * Returns the value of this {@code UnsignedInteger} as an {@code int}. This is an inverse
   * operation to {@link #fromIntBits}.

            

Reported by PMD.

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

Line: 32

               * @author Louis Wasserman
 */
public class ComparatorDelegationOverheadBenchmark {
  private final Integer[][] inputArrays = new Integer[0x100][];

  @Param({"10000"})
  int n;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 35

                private final Integer[][] inputArrays = new Integer[0x100][];

  @Param({"10000"})
  int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {

            

Reported by PMD.

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

Line: 37

                @Param({"10000"})
  int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {

            

Reported by PMD.

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

Line: 38

                int n;

  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 41

                void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'rng' (lines '39'-'47').
Error

Line: 39

              
  @BeforeExperiment
  void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '41'-'43').
Error

Line: 41

                void setUp() throws Exception {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }

            

Reported by PMD.

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

Line: 43

                  for (int i = 0; i < 0x100; i++) {
      Integer[] array = new Integer[n];
      for (int j = 0; j < n; j++) {
        array[j] = rng.nextInt();
      }
      inputArrays[i] = array;
    }
  }


            

Reported by PMD.

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

Line: 35

              public class SegmentBenchmark {

  @Param({"16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"})
  int capacity;

  private Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 37

                @Param({"16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"})
  int capacity;

  private Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {
    LocalCache<Object, Object> cache =
        new LocalCache<>(

            

Reported by PMD.

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

Line: 39

              
  private Segment<Object, Object> segment;

  @BeforeExperiment
  void setUp() {
    LocalCache<Object, Object> cache =
        new LocalCache<>(
            CacheBuilder.newBuilder().concurrencyLevel(1).initialCapacity(capacity), null);
    checkState(cache.segments.length == 1);

            

Reported by PMD.

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

Line: 46

                          CacheBuilder.newBuilder().concurrencyLevel(1).initialCapacity(capacity), null);
    checkState(cache.segments.length == 1);
    segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

                  segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

                  segment = cache.segments[0];
    checkState(segment.table.length() == capacity);
    for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")

            

Reported by PMD.

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

Line: 50

                  for (int i = 0; i < segment.threshold; i++) {
      cache.put(new Object(), new Object());
    }
    checkState(segment.table.length() == capacity);
  }

  @SuppressWarnings("GuardedBy")
  @Benchmark
  int time(int reps) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'oldTable' (lines '57'-'66').
Error

Line: 57

                @Benchmark
  int time(int reps) {
    int dummy = 0;
    AtomicReferenceArray<ReferenceEntry<Object, Object>> oldTable = segment.table;
    for (int i = 0; i < reps; i++) {
      // TODO(b/145386688): This access should be guarded by 'this.segment', which is not currently
      // held
      segment.expand();
      segment.table = oldTable;

            

Reported by PMD.

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

Line: 45

               * @author Louis Wasserman
 */
public class SafeTreeMapTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SafeTreeMapTest.class);
    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

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

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

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

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

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

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

  @GwtIncompatible // SerializableTester
  public static class ReserializedMapTests extends SortedMapInterfaceTest<String, Integer> {

            

Reported by PMD.

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

Line: 111

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

  @GwtIncompatible // SerializableTester
  public static class ReserializedMapTests extends SortedMapInterfaceTest<String, Integer> {
    public ReserializedMapTests() {

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 130

                  }

    @Override
    protected SortedMap<String, Integer> makeEmptyMap() throws UnsupportedOperationException {
      NavigableMap<String, Integer> map = new SafeTreeMap<>();
      return SerializableTester.reserialize(map);
    }

    @Override

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapForEachTester.java
8 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: 46

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapForEachTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachKnownOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    assertEquals(getOrderedElements(), entries);
  }

            

Reported by PMD.

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

Line: 49

                @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachKnownOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    assertEquals(getOrderedElements(), entries);
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER)
  public void testForEachUnknownOrder() {

            

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

                  assertEquals(getOrderedElements(), entries);
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER)
  public void testForEachUnknownOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    Helpers.assertEqualIgnoringOrder(getSampleEntries(), entries);
  }

            

Reported by PMD.

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

Line: 56

                @CollectionFeature.Require(absent = KNOWN_ORDER)
  public void testForEachUnknownOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    Helpers.assertEqualIgnoringOrder(getSampleEntries(), entries);
  }

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

                  Helpers.assertEqualIgnoringOrder(getSampleEntries(), entries);
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testForEach_nullKeys() {
    initMapWithNullKey();
    List<Entry<K, V>> expectedEntries = Arrays.asList(createArrayWithNullKey());
    List<Entry<K, V>> entries = new ArrayList<>();

            

Reported by PMD.

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

Line: 66

                  initMapWithNullKey();
    List<Entry<K, V>> expectedEntries = Arrays.asList(createArrayWithNullKey());
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    Helpers.assertEqualIgnoringOrder(expectedEntries, entries);
  }

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

                  Helpers.assertEqualIgnoringOrder(expectedEntries, entries);
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testForEach_nullValues() {
    initMapWithNullValue();
    List<Entry<K, V>> expectedEntries = Arrays.asList(createArrayWithNullValue());
    List<Entry<K, V>> entries = new ArrayList<>();

            

Reported by PMD.

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

Line: 76

                  initMapWithNullValue();
    List<Entry<K, V>> expectedEntries = Arrays.asList(createArrayWithNullValue());
    List<Entry<K, V>> entries = new ArrayList<>();
    getMap().forEach((k, v) -> entries.add(entry(k, v)));
    Helpers.assertEqualIgnoringOrder(expectedEntries, entries);
  }
}

            

Reported by PMD.

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

Line: 40

                private static final int[] binomials = new int[ARRAY_SIZE];

  @Param({"50", "1000", "10000"})
  int factorialBound;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      factorials[i] = RANDOM_SOURCE.nextInt(factorialBound);

            

Reported by PMD.

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

Line: 42

                @Param({"50", "1000", "10000"})
  int factorialBound;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      factorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
      slowFactorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
      binomials[i] = RANDOM_SOURCE.nextInt(factorials[i] + 1);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 53

              
  /** Previous version of BigIntegerMath.factorial, kept for timing purposes. */
  private static BigInteger oldSlowFactorial(int n) {
    if (n <= 20) {
      return BigInteger.valueOf(LongMath.factorial(n));
    } else {
      int k = 20;
      return BigInteger.valueOf(LongMath.factorial(k)).multiply(oldSlowFactorial(k, n));
    }

            

Reported by PMD.

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

Line: 57

                    return BigInteger.valueOf(LongMath.factorial(n));
    } else {
      int k = 20;
      return BigInteger.valueOf(LongMath.factorial(k)).multiply(oldSlowFactorial(k, n));
    }
  }

  /** Returns the product of {@code n1} exclusive through {@code n2} inclusive. */
  private static BigInteger oldSlowFactorial(int n1, int n2) {

            

Reported by PMD.

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

Line: 78

                   * Currently, we just divide the range in half.
     */
    int mid = (n1 + n2) >>> 1;
    return oldSlowFactorial(n1, mid).multiply(oldSlowFactorial(mid, n2));
  }

  @Benchmark
  int slowFactorial(int reps) {
    int tmp = 0;

            

Reported by PMD.

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

Line: 86

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      tmp += oldSlowFactorial(slowFactorials[j]).intValue();
    }
    return tmp;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 96

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      tmp += BigIntegerMath.factorial(factorials[j]).intValue();
    }
    return tmp;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 106

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & 0xffff;
      tmp += BigIntegerMath.binomial(factorials[j], binomials[j]).intValue();
    }
    return tmp;
  }
}

            

Reported by PMD.

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

Line: 46

               * @author Robert KonigsbergSortedMapFeature
 */
public class ForwardingSortedMapTest extends TestCase {
  static class StandardImplForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    private final SortedMap<K, V> backingSortedMap;

    StandardImplForwardingSortedMap(SortedMap<K, V> backingSortedMap) {
      this.backingSortedMap = backingSortedMap;
    }

            

Reported by PMD.

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

Line: 47

               */
public class ForwardingSortedMapTest extends TestCase {
  static class StandardImplForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    private final SortedMap<K, V> backingSortedMap;

    StandardImplForwardingSortedMap(SortedMap<K, V> backingSortedMap) {
      this.backingSortedMap = backingSortedMap;
    }


            

Reported by PMD.

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

Line: 108

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

    @Override

            

Reported by PMD.

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

Line: 129

                  }
  }

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

    suite.addTestSuite(ForwardingSortedMapTest.class);
    suite.addTest(
        SortedMapTestSuiteBuilder.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: 204

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 205

                }

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

            

Reported by PMD.

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

Line: 217

                          });
  }

  public void testEquals() {
    SortedMap<Integer, String> map1 = ImmutableSortedMap.of(1, "one");
    SortedMap<Integer, String> map2 = ImmutableSortedMap.of(2, "two");
    new EqualsTester()
        .addEqualityGroup(map1, wrap(map1), wrap(map1))
        .addEqualityGroup(map2, wrap(map2))

            

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

                          });
  }

  public void testEquals() {
    SortedMap<Integer, String> map1 = ImmutableSortedMap.of(1, "one");
    SortedMap<Integer, String> map2 = ImmutableSortedMap.of(2, "two");
    new EqualsTester()
        .addEqualityGroup(map1, wrap(map1), wrap(map1))
        .addEqualityGroup(map2, wrap(map2))

            

Reported by PMD.

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

Line: 37

               */
public class StreamsBenchmark {
  @Param({"1", "10", "100", "1000", "10000"})
  private int size;

  enum CollectionType {
    ARRAY_LIST(ArrayList::new),
    LINKED_LIST(LinkedList::new);


            

Reported by PMD.

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

Line: 50

                  }
  }

  @Param private CollectionType source;

  enum Operation {
    FIND_FIRST {
      @Override
      Object operate(Stream<?> stream) {

            

Reported by PMD.

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

Line: 65

                      try {
          return stream.collect(MoreCollectors.onlyElement());
        } catch (IllegalArgumentException | NoSuchElementException e) {
          throw new SkipThisScenarioException();
        }
      }
    },
    STREAMS_FIND_LAST {
      @Override

            

Reported by PMD.

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

Line: 84

                  REDUCE_LAST_PARALLEL {
      @Override
      Object operate(Stream<?> stream) {
        return stream.parallel().reduce((a, b) -> b);
      }
    };

    abstract Object operate(Stream<?> stream);
  }

            

Reported by PMD.

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

Line: 91

                  abstract Object operate(Stream<?> stream);
  }

  @Param private Operation operation;

  Collection<Object> collection;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 93

              
  @Param private Operation operation;

  Collection<Object> collection;

  @BeforeExperiment
  void setUp() {
    collection = source.supplier.get();
    for (int i = 0; i < size; i++) {

            

Reported by PMD.

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

Line: 95

              
  Collection<Object> collection;

  @BeforeExperiment
  void setUp() {
    collection = source.supplier.get();
    for (int i = 0; i < size; i++) {
      collection.add(new Object());
    }

            

Reported by PMD.

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

Line: 97

              
  @BeforeExperiment
  void setUp() {
    collection = source.supplier.get();
    for (int i = 0; i < size; i++) {
      collection.add(new Object());
    }
  }


            

Reported by PMD.

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

Line: 34

                static final int SAMPLE_MASK = 0x0FFF;

  @Param("1234")
  int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;

            

Reported by PMD.

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

Line: 36

                @Param("1234")
  int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;


            

Reported by PMD.

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

Line: 37

                int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

            

Reported by PMD.

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

Line: 39

                int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

            

Reported by PMD.

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

Line: 40

                int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;


            

Reported by PMD.

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

Line: 42

                long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

  @BeforeExperiment
  void 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: 46

              
  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

  @BeforeExperiment
  void setUp() {
    Random random = new Random(randomSeed);
    xInts = new int[SAMPLE_SIZE];
    yInts = new int[SAMPLE_SIZE];
    xLongs = new long[SAMPLE_SIZE];

            

Reported by PMD.

Found 'DU'-anomaly for variable 'random' (lines '48'-'61').
Error

Line: 48

              
  @BeforeExperiment
  void setUp() {
    Random random = new Random(randomSeed);
    xInts = new int[SAMPLE_SIZE];
    yInts = new int[SAMPLE_SIZE];
    xLongs = new long[SAMPLE_SIZE];
    yLongs = new long[SAMPLE_SIZE];
    constant = new int[SAMPLE_SIZE];

            

Reported by PMD.