The following issues were found

guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java
4 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 29

               */
@GwtCompatible
public class ConflictingRequirementsException extends Exception {
  private Set<Feature<?>> conflicts;
  private Object source;

  public ConflictingRequirementsException(
      String message, Set<Feature<?>> conflicts, Object source) {
    super(message);

            

Reported by PMD.

Private field 'conflicts' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 29

               */
@GwtCompatible
public class ConflictingRequirementsException extends Exception {
  private Set<Feature<?>> conflicts;
  private Object source;

  public ConflictingRequirementsException(
      String message, Set<Feature<?>> conflicts, Object source) {
    super(message);

            

Reported by PMD.

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

Line: 30

              @GwtCompatible
public class ConflictingRequirementsException extends Exception {
  private Set<Feature<?>> conflicts;
  private Object source;

  public ConflictingRequirementsException(
      String message, Set<Feature<?>> conflicts, Object source) {
    super(message);
    this.conflicts = conflicts;

            

Reported by PMD.

Private field 'source' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 30

              @GwtCompatible
public class ConflictingRequirementsException extends Exception {
  private Set<Feature<?>> conflicts;
  private Object source;

  public ConflictingRequirementsException(
      String message, Set<Feature<?>> conflicts, Object source) {
    super(message);
    this.conflicts = conflicts;

            

Reported by PMD.

guava/src/com/google/common/primitives/ParseRequest.java
4 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 23

              @GwtCompatible
@ElementTypesAreNonnullByDefault
final class ParseRequest {
  final String rawValue;
  final int radix;

  private ParseRequest(String rawValue, int radix) {
    this.rawValue = rawValue;
    this.radix = radix;

            

Reported by PMD.

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

Line: 24

              @ElementTypesAreNonnullByDefault
final class ParseRequest {
  final String rawValue;
  final int radix;

  private ParseRequest(String rawValue, int radix) {
    this.rawValue = rawValue;
    this.radix = radix;
  }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 43

                  if (stringValue.startsWith("0x") || stringValue.startsWith("0X")) {
      rawValue = stringValue.substring(2);
      radix = 16;
    } else if (firstChar == '#') {
      rawValue = stringValue.substring(1);
      radix = 16;
    } else if (firstChar == '0' && stringValue.length() > 1) {
      rawValue = stringValue.substring(1);
      radix = 8;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'firstChar' (lines '39'-'55').
Error

Line: 39

                  // Handle radix specifier if present
    String rawValue;
    int radix;
    char firstChar = stringValue.charAt(0);
    if (stringValue.startsWith("0x") || stringValue.startsWith("0X")) {
      rawValue = stringValue.substring(2);
      radix = 16;
    } else if (firstChar == '#') {
      rawValue = stringValue.substring(1);

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/ForwardingObjectTesterTest.java
4 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: 29

               */
public class ForwardingObjectTesterTest extends TestCase {

  public void testFailsToForward() {
    try {
      ForwardingObjectTester.testForwardingObject(FailToForward.class);
    } catch (AssertionError | UnsupportedOperationException expected) {
      // UnsupportedOperationException is what we see on Android.
      return;

            

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

                  fail("Should have thrown");
  }

  @AndroidIncompatible // TODO(cpovirk): java.lang.IllegalAccessError: superclass not accessible
  public void testSuccessfulForwarding() {
    ForwardingObjectTester.testForwardingObject(ForwardToDelegate.class);
  }

  private abstract static class FailToForward extends ForwardingObject implements Runnable {

            

Reported by PMD.

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

Line: 40

                }

  @AndroidIncompatible // TODO(cpovirk): java.lang.IllegalAccessError: superclass not accessible
  public void testSuccessfulForwarding() {
    ForwardingObjectTester.testForwardingObject(ForwardToDelegate.class);
  }

  private abstract static class FailToForward extends ForwardingObject implements Runnable {
    @Override

            

Reported by PMD.

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

Line: 52

                private abstract static class ForwardToDelegate extends ForwardingObject implements Runnable {
    @Override
    public void run() {
      delegate().run();
    }

    @Override
    protected abstract Runnable delegate();
  }

            

Reported by PMD.

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

Line: 51

              @ElementTypesAreNonnullByDefault
public final class EvictingQueue<E> extends ForwardingQueue<E> implements Serializable {

  private final Queue<E> delegate;

  @VisibleForTesting final int maxSize;

  private EvictingQueue(int maxSize) {
    checkArgument(maxSize >= 0, "maxSize (%s) must >= 0", maxSize);

            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 51

              @ElementTypesAreNonnullByDefault
public final class EvictingQueue<E> extends ForwardingQueue<E> implements Serializable {

  private final Queue<E> delegate;

  @VisibleForTesting final int maxSize;

  private EvictingQueue(int maxSize) {
    checkArgument(maxSize >= 0, "maxSize (%s) must >= 0", maxSize);

            

Reported by PMD.

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

Line: 53

              
  private final Queue<E> delegate;

  @VisibleForTesting final int maxSize;

  private EvictingQueue(int maxSize) {
    checkArgument(maxSize >= 0, "maxSize (%s) must >= 0", maxSize);
    this.delegate = new ArrayDeque<E>(maxSize);
    this.maxSize = maxSize;

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 130

                }

  @Override
  public Object[] toArray() {
    /*
     * If we could, we'd declare the no-arg `Collection.toArray()` to return "Object[] but elements
     * have the same nullness as E." Since we can't, we declare it to return nullable elements, and
     * we can override it in our non-null-guaranteeing subtypes to present a better signature to
     * their users.

            

Reported by PMD.

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

Line: 46

              @ElementTypesAreNonnullByDefault
abstract class AbstractDirectedNetworkConnections<N, E> implements NetworkConnections<N, E> {
  /** Keys are edges incoming to the origin node, values are the source node. */
  final Map<E, N> inEdgeMap;

  /** Keys are edges outgoing from the origin node, values are the target node. */
  final Map<E, N> outEdgeMap;

  private int selfLoopCount;

            

Reported by PMD.

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

Line: 49

                final Map<E, N> inEdgeMap;

  /** Keys are edges outgoing from the origin node, values are the target node. */
  final Map<E, N> outEdgeMap;

  private int selfLoopCount;

  AbstractDirectedNetworkConnections(Map<E, N> inEdgeMap, Map<E, N> outEdgeMap, int selfLoopCount) {
    this.inEdgeMap = checkNotNull(inEdgeMap);

            

Reported by PMD.

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

Line: 51

                /** Keys are edges outgoing from the origin node, values are the target node. */
  final Map<E, N> outEdgeMap;

  private int selfLoopCount;

  AbstractDirectedNetworkConnections(Map<E, N> inEdgeMap, Map<E, N> outEdgeMap, int selfLoopCount) {
    this.inEdgeMap = checkNotNull(inEdgeMap);
    this.outEdgeMap = checkNotNull(outEdgeMap);
    this.selfLoopCount = checkNonNegative(selfLoopCount);

            

Reported by PMD.

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

Line: 74

                          (selfLoopCount == 0)
                ? Iterables.concat(inEdgeMap.keySet(), outEdgeMap.keySet())
                : Sets.union(inEdgeMap.keySet(), outEdgeMap.keySet());
        return Iterators.unmodifiableIterator(incidentEdges.iterator());
      }

      @Override
      public int size() {
        return IntMath.saturatedAdd(inEdgeMap.size(), outEdgeMap.size() - selfLoopCount);

            

Reported by PMD.

guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
4 issues
Field elementSet has the same name as a method
Error

Line: 42

                static final ImmutableSortedMultiset<Comparable> NATURAL_EMPTY_MULTISET =
      new RegularImmutableSortedMultiset<>(Ordering.natural());

  @VisibleForTesting final transient RegularImmutableSortedSet<E> elementSet;
  private final transient long[] cumulativeCounts;
  private final transient int offset;
  private final transient int length;

  RegularImmutableSortedMultiset(Comparator<? super E> comparator) {

            

Reported by PMD.

The user-supplied array 'cumulativeCounts' is stored directly.
Design

Line: 55

                }

  RegularImmutableSortedMultiset(
      RegularImmutableSortedSet<E> elementSet, long[] cumulativeCounts, int offset, int length) {
    this.elementSet = elementSet;
    this.cumulativeCounts = cumulativeCounts;
    this.offset = offset;
    this.length = length;
  }

            

Reported by PMD.

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

Line: 68

              
  @Override
  Entry<E> getEntry(int index) {
    return Multisets.immutableEntry(elementSet.asList().get(index), getCount(index));
  }

  @Override
  public void forEachEntry(ObjIntConsumer<? super E> action) {
    checkNotNull(action);

            

Reported by PMD.

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

Line: 75

                public void forEachEntry(ObjIntConsumer<? super E> action) {
    checkNotNull(action);
    for (int i = 0; i < length; i++) {
      action.accept(elementSet.asList().get(i), getCount(i));
    }
  }

  @Override
  @CheckForNull

            

Reported by PMD.

guava/src/com/google/common/collect/CompactHashing.java
4 issues
Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 166

                    Object table,
      int[] entries,
      @Nullable Object[] keys,
      @CheckForNull @Nullable Object[] values) {
    int hash = Hashing.smearedHash(key);
    int tableIndex = hash & mask;
    int next = tableGet(table, tableIndex);
    if (next == UNSET) {
      return -1;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'lastEntryIndex' (lines '174'-'192').
Error

Line: 174

                    return -1;
    }
    int hashPrefix = getHashPrefix(hash, mask);
    int lastEntryIndex = -1;
    do {
      int entryIndex = next - 1;
      int entry = entries[entryIndex];
      if (getHashPrefix(entry, mask) == hashPrefix
          && Objects.equal(key, keys[entryIndex])

            

Reported by PMD.

Found 'DU'-anomaly for variable 'lastEntryIndex' (lines '192'-'196').
Error

Line: 192

              
        return entryIndex;
      }
      lastEntryIndex = entryIndex;
      next = getNext(entry, mask);
    } while (next != UNSET);
    return -1;
  }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'lastEntryIndex' (lines '192'-'192').
Error

Line: 192

              
        return entryIndex;
      }
      lastEntryIndex = entryIndex;
      next = getNext(entry, mask);
    } while (next != UNSET);
    return -1;
  }
}

            

Reported by PMD.

guava/src/com/google/common/collect/CompactLinkedHashMap.java
4 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 57

               */
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactLinkedHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends CompactHashMap<K, V> {
  // TODO(lowasser): implement removeEldestEntry so this can be used as a drop-in replacement

  /** Creates an empty {@code CompactLinkedHashMap} instance. */
  public static <K extends @Nullable Object, V extends @Nullable Object>

            

Reported by PMD.

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

Line: 58

              @GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactLinkedHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends CompactHashMap<K, V> {
  // TODO(lowasser): implement removeEldestEntry so this can be used as a drop-in replacement

  /** Creates an empty {@code CompactLinkedHashMap} instance. */
  public static <K extends @Nullable Object, V extends @Nullable Object>
      CompactLinkedHashMap<K, V> create() {

            

Reported by PMD.

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

Line: 100

                /** Pointer to the last node in the linked list, or {@code ENDPOINT} if there are no entries. */
  private transient int lastEntry;

  private final boolean accessOrder;

  CompactLinkedHashMap() {
    this(CompactHashing.DEFAULT_SIZE);
  }


            

Reported by PMD.

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

Line: 138

                @CanIgnoreReturnValue
  Map<K, V> convertToHashFloodingResistantImplementation() {
    Map<K, V> result = super.convertToHashFloodingResistantImplementation();
    links = null;
    return result;
  }

  /*
   * For discussion of the safety of the following methods for operating on predecessors and

            

Reported by PMD.

guava/src/com/google/common/collect/AbstractMapEntry.java
4 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 54

                public boolean equals(@CheckForNull Object object) {
    if (object instanceof Entry) {
      Entry<?, ?> that = (Entry<?, ?>) object;
      return Objects.equal(this.getKey(), that.getKey())
          && Objects.equal(this.getValue(), that.getValue());
    }
    return false;
  }


            

Reported by PMD.

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

Line: 55

                  if (object instanceof Entry) {
      Entry<?, ?> that = (Entry<?, ?>) object;
      return Objects.equal(this.getKey(), that.getKey())
          && Objects.equal(this.getValue(), that.getValue());
    }
    return false;
  }

  @Override

            

Reported by PMD.

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

Line: 64

                public int hashCode() {
    K k = getKey();
    V v = getValue();
    return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
  }

  /** Returns a string representation of the form {@code {key}={value}}. */
  @Override
  public String toString() {

            

Reported by PMD.

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

Line: 64

                public int hashCode() {
    K k = getKey();
    V v = getValue();
    return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
  }

  /** Returns a string representation of the form {@code {key}={value}}. */
  @Override
  public String toString() {

            

Reported by PMD.

guava/src/com/google/common/collect/Comparators.java
4 issues
Found 'DU'-anomaly for variable 'prev' (lines '82'-'92').
Error

Line: 82

                  checkNotNull(comparator);
    Iterator<? extends T> it = iterable.iterator();
    if (it.hasNext()) {
      T prev = it.next();
      while (it.hasNext()) {
        T next = it.next();
        if (comparator.compare(prev, next) > 0) {
          return false;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'prev' (lines '88'-'92').
Error

Line: 88

                      if (comparator.compare(prev, next) > 0) {
          return false;
        }
        prev = next;
      }
    }
    return true;
  }


            

Reported by PMD.

Found 'DU'-anomaly for variable 'prev' (lines '105'-'115').
Error

Line: 105

                  checkNotNull(comparator);
    Iterator<? extends T> it = iterable.iterator();
    if (it.hasNext()) {
      T prev = it.next();
      while (it.hasNext()) {
        T next = it.next();
        if (comparator.compare(prev, next) >= 0) {
          return false;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'prev' (lines '111'-'115').
Error

Line: 111

                      if (comparator.compare(prev, next) >= 0) {
          return false;
        }
        prev = next;
      }
    }
    return true;
  }


            

Reported by PMD.