The following issues were found

guava/src/com/google/common/collect/Interners.java
7 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 44

                 * @since 21.0
   */
  public static class InternerBuilder {
    private final MapMaker mapMaker = new MapMaker();
    private boolean strong = true;

    private InternerBuilder() {}

    /**

            

Reported by PMD.

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

Line: 45

                 */
  public static class InternerBuilder {
    private final MapMaker mapMaker = new MapMaker();
    private boolean strong = true;

    private InternerBuilder() {}

    /**
     * Instructs the {@link InternerBuilder} to build a strong interner.

            

Reported by PMD.

Field strong has the same name as a method
Error

Line: 45

                 */
  public static class InternerBuilder {
    private final MapMaker mapMaker = new MapMaker();
    private boolean strong = true;

    private InternerBuilder() {}

    /**
     * Instructs the {@link InternerBuilder} to build a strong interner.

            

Reported by PMD.

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

Line: 116

                @VisibleForTesting
  static final class InternerImpl<E> implements Interner<E> {
    // MapMaker is our friend, we know about this type
    @VisibleForTesting final MapMakerInternalMap<E, Dummy, ?, ?> map;

    private InternerImpl(MapMaker mapMaker) {
      this.map =
          MapMakerInternalMap.createWithDummyValues(mapMaker.keyEquivalence(Equivalence.equals()));
    }

            

Reported by PMD.

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

Line: 130

                      @SuppressWarnings("rawtypes") // using raw types to avoid a bug in our nullness checker :(
        InternalEntry entry = map.getEntry(sample);
        if (entry != null) {
          Object canonical = entry.getKey();
          if (canonical != null) { // only matters if weak/soft keys are used
            // The compiler would know this is safe if not for our use of raw types (see above).
            @SuppressWarnings("unchecked")
            E result = (E) canonical;
            return result;

            

Reported by PMD.

Avoid empty if statements
Error

Line: 143

                      Dummy sneaky = map.putIfAbsent(sample, Dummy.VALUE);
        if (sneaky == null) {
          return sample;
        } else {
          /* Someone beat us to it! Trying again...
           *
           * Technically this loop not guaranteed to terminate, so theoretically (extremely
           * unlikely) this thread might starve, but even then, there is always going to be another
           * thread doing progress here.

            

Reported by PMD.

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

Line: 166

              
  private static class InternerFunction<E> implements Function<E, E> {

    private final Interner<E> interner;

    public InternerFunction(Interner<E> interner) {
      this.interner = interner;
    }


            

Reported by PMD.

guava/src/com/google/common/collect/StandardRowSortedTable.java
7 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 75

                 */
  @Override
  public SortedSet<R> rowKeySet() {
    return (SortedSet<R>) rowMap().keySet();
  }

  /**
   * {@inheritDoc}
   *

            

Reported by PMD.

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

Line: 109

                  @Override
    @CheckForNull
    public Comparator<? super R> comparator() {
      return sortedBackingMap().comparator();
    }

    @Override
    public R firstKey() {
      return sortedBackingMap().firstKey();

            

Reported by PMD.

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

Line: 114

              
    @Override
    public R firstKey() {
      return sortedBackingMap().firstKey();
    }

    @Override
    public R lastKey() {
      return sortedBackingMap().lastKey();

            

Reported by PMD.

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

Line: 119

              
    @Override
    public R lastKey() {
      return sortedBackingMap().lastKey();
    }

    @Override
    public SortedMap<R, Map<C, V>> headMap(R toKey) {
      checkNotNull(toKey);

            

Reported by PMD.

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

Line: 125

                  @Override
    public SortedMap<R, Map<C, V>> headMap(R toKey) {
      checkNotNull(toKey);
      return new StandardRowSortedTable<R, C, V>(sortedBackingMap().headMap(toKey), factory)
          .rowMap();
    }

    @Override
    public SortedMap<R, Map<C, V>> subMap(R fromKey, R toKey) {

            

Reported by PMD.

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

Line: 133

                  public SortedMap<R, Map<C, V>> subMap(R fromKey, R toKey) {
      checkNotNull(fromKey);
      checkNotNull(toKey);
      return new StandardRowSortedTable<R, C, V>(sortedBackingMap().subMap(fromKey, toKey), factory)
          .rowMap();
    }

    @Override
    public SortedMap<R, Map<C, V>> tailMap(R fromKey) {

            

Reported by PMD.

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

Line: 140

                  @Override
    public SortedMap<R, Map<C, V>> tailMap(R fromKey) {
      checkNotNull(fromKey);
      return new StandardRowSortedTable<R, C, V>(sortedBackingMap().tailMap(fromKey), factory)
          .rowMap();
    }
  }

  private static final long serialVersionUID = 0;

            

Reported by PMD.

guava/src/com/google/common/graph/MultiEdgesConnecting.java
7 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 41

              @ElementTypesAreNonnullByDefault
abstract class MultiEdgesConnecting<E> extends AbstractSet<E> {

  private final Map<E, ?> outEdgeToNode;
  private final Object targetNode;

  MultiEdgesConnecting(Map<E, ?> outEdgeToNode, Object targetNode) {
    this.outEdgeToNode = checkNotNull(outEdgeToNode);
    this.targetNode = checkNotNull(targetNode);

            

Reported by PMD.

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

Line: 42

              abstract class MultiEdgesConnecting<E> extends AbstractSet<E> {

  private final Map<E, ?> outEdgeToNode;
  private final Object targetNode;

  MultiEdgesConnecting(Map<E, ?> outEdgeToNode, Object targetNode) {
    this.outEdgeToNode = checkNotNull(outEdgeToNode);
    this.targetNode = checkNotNull(targetNode);
  }

            

Reported by PMD.

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

Line: 51

              
  @Override
  public UnmodifiableIterator<E> iterator() {
    final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
    return new AbstractIterator<E>() {
      @Override
      @CheckForNull
      protected E computeNext() {
        while (entries.hasNext()) {

            

Reported by PMD.

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

Line: 58

                    protected E computeNext() {
        while (entries.hasNext()) {
          Entry<E, ?> entry = entries.next();
          if (targetNode.equals(entry.getValue())) {
            return entry.getKey();
          }
        }
        return endOfData();
      }

            

Reported by PMD.

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

Line: 59

                      while (entries.hasNext()) {
          Entry<E, ?> entry = entries.next();
          if (targetNode.equals(entry.getValue())) {
            return entry.getKey();
          }
        }
        return endOfData();
      }
    };

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entries' (lines '51'-'65').
Error

Line: 51

              
  @Override
  public UnmodifiableIterator<E> iterator() {
    final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
    return new AbstractIterator<E>() {
      @Override
      @CheckForNull
      protected E computeNext() {
        while (entries.hasNext()) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entries' (lines '51'-'65').
Error

Line: 51

              
  @Override
  public UnmodifiableIterator<E> iterator() {
    final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
    return new AbstractIterator<E>() {
      @Override
      @CheckForNull
      protected E computeNext() {
        while (entries.hasNext()) {

            

Reported by PMD.

guava/src/com/google/common/cache/ForwardingLoadingCache.java
7 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 46

              
  @Override
  public V get(K key) throws ExecutionException {
    return delegate().get(key);
  }

  @Override
  public V getUnchecked(K key) {
    return delegate().getUnchecked(key);

            

Reported by PMD.

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

Line: 51

              
  @Override
  public V getUnchecked(K key) {
    return delegate().getUnchecked(key);
  }

  @Override
  public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
    return delegate().getAll(keys);

            

Reported by PMD.

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

Line: 56

              
  @Override
  public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
    return delegate().getAll(keys);
  }

  @Override
  public V apply(K key) {
    return delegate().apply(key);

            

Reported by PMD.

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

Line: 61

              
  @Override
  public V apply(K key) {
    return delegate().apply(key);
  }

  @Override
  public void refresh(K key) {
    delegate().refresh(key);

            

Reported by PMD.

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

Line: 66

              
  @Override
  public void refresh(K key) {
    delegate().refresh(key);
  }

  /**
   * A simplified version of {@link ForwardingLoadingCache} where subclasses can pass in an already
   * constructed {@link LoadingCache} as the delegate.

            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 77

                 */
  public abstract static class SimpleForwardingLoadingCache<K, V>
      extends ForwardingLoadingCache<K, V> {
    private final LoadingCache<K, V> delegate;

    protected SimpleForwardingLoadingCache(LoadingCache<K, V> delegate) {
      this.delegate = Preconditions.checkNotNull(delegate);
    }


            

Reported by PMD.

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

Line: 77

                 */
  public abstract static class SimpleForwardingLoadingCache<K, V>
      extends ForwardingLoadingCache<K, V> {
    private final LoadingCache<K, V> delegate;

    protected SimpleForwardingLoadingCache(LoadingCache<K, V> delegate) {
      this.delegate = Preconditions.checkNotNull(delegate);
    }


            

Reported by PMD.

guava/src/com/google/common/collect/ImmutableCollection.java
7 issues
Return an empty array rather than null.
Error

Line: 230

              
  /** If this collection is backed by an array of its elements in insertion order, returns it. */
  @CheckForNull
  Object[] internalArray() {
    return null;
  }

  /**
   * If this collection is backed by an array of its elements in insertion order, returns the offset

            

Reported by PMD.

Avoid reassigning parameters such as 'other'
Design

Line: 211

                 * nullness perspective. The signature below at least has the virtue of being relatively simple.
   */
  @SuppressWarnings("nullness")
  public final <T extends @Nullable Object> T[] toArray(T[] other) {
    checkNotNull(other);
    int size = size();

    if (other.length < size) {
      Object[] internal = internalArray();

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 383

                 * offset. Returns {@code offset + size()}.
   */
  @CanIgnoreReturnValue
  int copyIntoArray(@Nullable Object[] dst, int offset) {
    for (E e : this) {
      dst[offset++] = e;
    }
    return offset;
  }

            

Reported by PMD.

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

Line: 169

              @ElementTypesAreNonnullByDefault
// TODO(kevinb): I think we should push everything down to "BaseImmutableCollection" or something,
// just to do everything we can to emphasize the "practically an interface" nature of this class.
public abstract class ImmutableCollection<E> extends AbstractCollection<E> implements Serializable {
  /*
   * We expect SIZED (and SUBSIZED, if applicable) to be added by the spliterator factory methods.
   * These are properties of the collection as a whole; SIZED and SUBSIZED are more properties of
   * the spliterator implementation.
   */

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 222

                    }
      other = ObjectArrays.newArray(other, size);
    } else if (other.length > size) {
      other[size] = null;
    }
    copyIntoArray(other, 0);
    return other;
  }


            

Reported by PMD.

The String literal 'Always throws UnsupportedOperationException' appears 7 times in this file; the first occurrence is on line 262
Error

Line: 262

                @CanIgnoreReturnValue
  @Deprecated
  @Override
  @DoNotCall("Always throws UnsupportedOperationException")
  public final boolean add(E e) {
    throw new UnsupportedOperationException();
  }

  /**

            

Reported by PMD.

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

Line: 364

                    case 0:
        return ImmutableList.of();
      case 1:
        return ImmutableList.of(iterator().next());
      default:
        return new RegularImmutableAsList<E>(this, toArray());
    }
  }


            

Reported by PMD.

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

Line: 41

               * @author Louis Wasserman
 */
public class ForwardingSortedSetTest extends TestCase {
  static class StandardImplForwardingSortedSet<T> extends ForwardingSortedSet<T> {
    private final SortedSet<T> backingSortedSet;

    StandardImplForwardingSortedSet(SortedSet<T> backingSortedSet) {
      this.backingSortedSet = backingSortedSet;
    }

            

Reported by PMD.

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

Line: 42

               */
public class ForwardingSortedSetTest extends TestCase {
  static class StandardImplForwardingSortedSet<T> extends ForwardingSortedSet<T> {
    private final SortedSet<T> backingSortedSet;

    StandardImplForwardingSortedSet(SortedSet<T> backingSortedSet) {
      this.backingSortedSet = backingSortedSet;
    }


            

Reported by PMD.

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

Line: 119

                  }
  }

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

    suite.addTestSuite(ForwardingSortedSetTest.class);
    suite.addTest(
        SortedSetTestSuiteBuilder.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: 147

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 148

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            SortedSet.class,
            new Function<SortedSet, SortedSet>() {
              @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: 160

                          });
  }

  public void testEquals() {
    SortedSet<String> set1 = ImmutableSortedSet.of("one");
    SortedSet<String> set2 = ImmutableSortedSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

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

Line: 160

                          });
  }

  public void testEquals() {
    SortedSet<String> set1 = ImmutableSortedSet.of("one");
    SortedSet<String> set2 = ImmutableSortedSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

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

Line: 42

               * @author Louis Wasserman
 */
public class ForwardingSetTest extends TestCase {
  static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
    private final Set<T> backingSet;

    StandardImplForwardingSet(Set<T> backingSet) {
      this.backingSet = backingSet;
    }

            

Reported by PMD.

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

Line: 43

               */
public class ForwardingSetTest extends TestCase {
  static class StandardImplForwardingSet<T> extends ForwardingSet<T> {
    private final Set<T> backingSet;

    StandardImplForwardingSet(Set<T> backingSet) {
      this.backingSet = backingSet;
    }


            

Reported by PMD.

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

Line: 115

                  }
  }

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

    suite.addTestSuite(ForwardingSetTest.class);
    suite.addTest(
        SetTestSuiteBuilder.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: 148

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 149

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Set.class,
            new Function<Set, 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: 161

                          });
  }

  public void testEquals() {
    Set<String> set1 = ImmutableSet.of("one");
    Set<String> set2 = ImmutableSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

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

Line: 161

                          });
  }

  public void testEquals() {
    Set<String> set1 = ImmutableSet.of("one");
    Set<String> set2 = ImmutableSet.of("two");
    new EqualsTester()
        .addEqualityGroup(set1, wrap(set1), wrap(set1))
        .addEqualityGroup(set2, wrap(set2))

            

Reported by PMD.

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

Line: 42

               * @author Louis Wasserman
 */
public class ForwardingListTest extends TestCase {
  static final class StandardImplForwardingList<T> extends ForwardingList<T> {
    private final List<T> backingList;

    StandardImplForwardingList(List<T> backingList) {
      this.backingList = backingList;
    }

            

Reported by PMD.

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

Line: 43

               */
public class ForwardingListTest extends TestCase {
  static final class StandardImplForwardingList<T> extends ForwardingList<T> {
    private final List<T> backingList;

    StandardImplForwardingList(List<T> backingList) {
      this.backingList = backingList;
    }


            

Reported by PMD.

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

Line: 155

                  }
  }

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

    suite.addTestSuite(ForwardingListTest.class);
    suite.addTest(
        ListTestSuiteBuilder.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: 190

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 191

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            List.class,
            new Function<List, List>() {
              @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: 203

                          });
  }

  public void testEquals() {
    List<String> list1 = ImmutableList.of("one");
    List<String> list2 = ImmutableList.of("two");
    new EqualsTester()
        .addEqualityGroup(list1, wrap(list1), wrap(list1))
        .addEqualityGroup(list2, wrap(list2))

            

Reported by PMD.

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

Line: 203

                          });
  }

  public void testEquals() {
    List<String> list1 = ImmutableList.of("one");
    List<String> list2 = ImmutableList.of("two");
    new EqualsTester()
        .addEqualityGroup(list1, wrap(list1), wrap(list1))
        .addEqualityGroup(list2, wrap(list2))

            

Reported by PMD.

guava-tests/benchmark/com/google/common/util/concurrent/CycleDetectingLockFactoryBenchmark.java
7 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

              public class CycleDetectingLockFactoryBenchmark {

  @Param({"2", "3", "4", "5", "10"})
  int lockNestingDepth;

  CycleDetectingLockFactory factory;
  private Lock[] plainLocks;
  private Lock[] detectingLocks;


            

Reported by PMD.

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

Line: 35

                @Param({"2", "3", "4", "5", "10"})
  int lockNestingDepth;

  CycleDetectingLockFactory factory;
  private Lock[] plainLocks;
  private Lock[] detectingLocks;

  @BeforeExperiment
  void setUp() throws Exception {

            

Reported by PMD.

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

Line: 36

                int lockNestingDepth;

  CycleDetectingLockFactory factory;
  private Lock[] plainLocks;
  private Lock[] detectingLocks;

  @BeforeExperiment
  void setUp() throws Exception {
    this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);

            

Reported by PMD.

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

Line: 37

              
  CycleDetectingLockFactory factory;
  private Lock[] plainLocks;
  private Lock[] detectingLocks;

  @BeforeExperiment
  void setUp() throws Exception {
    this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
    this.plainLocks = new Lock[lockNestingDepth];

            

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 Lock[] plainLocks;
  private Lock[] detectingLocks;

  @BeforeExperiment
  void setUp() throws Exception {
    this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
    this.plainLocks = new Lock[lockNestingDepth];
    for (int i = 0; i < lockNestingDepth; i++) {
      plainLocks[i] = new ReentrantLock();

            

Reported by PMD.

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

Line: 40

                private Lock[] detectingLocks;

  @BeforeExperiment
  void setUp() throws Exception {
    this.factory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.WARN);
    this.plainLocks = new Lock[lockNestingDepth];
    for (int i = 0; i < lockNestingDepth; i++) {
      plainLocks[i] = new ReentrantLock();
    }

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 81

              
  private static void lockAndUnlockNested(Lock[] locks, int reps) {
    for (int i = 0; i < reps; i++) {
      for (int j = 0; j < locks.length; j++) {
        locks[j].lock();
      }
      for (int j = locks.length - 1; j >= 0; j--) {
        locks[j].unlock();
      }

            

Reported by PMD.

guava-tests/benchmark/com/google/common/math/IntMathBenchmark.java
7 issues
Field factorial has the same name as a method
Error

Line: 36

               */
public class IntMathBenchmark {
  private static int[] exponent = new int[ARRAY_SIZE];
  private static int[] factorial = new int[ARRAY_SIZE];
  private static int[] binomial = new int[ARRAY_SIZE];
  private static final int[] positive = new int[ARRAY_SIZE];
  private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];


            

Reported by PMD.

Field binomial has the same name as a method
Error

Line: 37

              public class IntMathBenchmark {
  private static int[] exponent = new int[ARRAY_SIZE];
  private static int[] factorial = new int[ARRAY_SIZE];
  private static int[] binomial = new int[ARRAY_SIZE];
  private static final int[] positive = new int[ARRAY_SIZE];
  private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];

  @BeforeExperiment

            

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

                private static final int[] nonnegative = new int[ARRAY_SIZE];
  private static final int[] ints = new int[ARRAY_SIZE];

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      exponent[i] = randomExponent();
      factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);

            

Reported by PMD.

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

Line: 48

                    exponent[i] = randomExponent();
      factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
      positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
      nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
      ints[i] = RANDOM_SOURCE.nextInt();
    }
  }


            

Reported by PMD.

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

Line: 49

                    factorial[i] = RANDOM_SOURCE.nextInt(50);
      binomial[i] = RANDOM_SOURCE.nextInt(factorial[i] + 1);
      positive[i] = randomPositiveBigInteger(Integer.SIZE - 1).intValue();
      nonnegative[i] = randomNonNegativeBigInteger(Integer.SIZE - 1).intValue();
      ints[i] = RANDOM_SOURCE.nextInt();
    }
  }

  @Benchmark

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '106'-'110').
Error

Line: 106

              
  @Benchmark
  int isPrime(int reps) {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (IntMath.isPrime(positive[j])) {
        tmp++;
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '110'-'110').
Error

Line: 110

                  for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (IntMath.isPrime(positive[j])) {
        tmp++;
      }
    }
    return tmp;
  }
}

            

Reported by PMD.