The following issues were found

guava/src/com/google/common/cache/LongAdder.java
8 issues
This class has too many methods, consider refactoring it.
Design

Line: 44

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class LongAdder extends Striped64 implements Serializable, LongAddable {
  private static final long serialVersionUID = 7249069246863182397L;

  /** Version of plus for use in retryUpdate */
  @Override
  final long fn(long v, long x) {

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 68

                  int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 70

                  int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);
    }

            

Reported by PMD.

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

Line: 191

                private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    s.defaultReadObject();
    busy = 0;
    cells = null;
    base = s.readLong();
  }
}

            

Reported by PMD.

Use one line for each declaration, it enhances code readability.
Design

Line: 64

                @Override
  public void add(long x) {
    Cell[] as;
    long b, v;
    int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'as' (lines '68'-'76').
Error

Line: 68

                  int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null

            

Reported by PMD.

Found 'DD'-anomaly for variable 'uncontended' (lines '69'-'70').
Error

Line: 69

                  Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'uncontended' (lines '70'-'76').
Error

Line: 70

                  int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);
    }

            

Reported by PMD.

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapForEachTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testForEach() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }


            

Reported by PMD.

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

Line: 40

              public class MultimapForEachTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testForEach() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachOrder() {

            

Reported by PMD.

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

Line: 41

                public void testForEach() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();

            

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

                  assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

            

Reported by PMD.

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

Line: 47

                @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }
}

            

Reported by PMD.

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

Line: 48

                public void testForEachOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entries' (lines '39'-'42').
Error

Line: 39

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapForEachTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testForEach() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionFeature.Require(KNOWN_ORDER)

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entries' (lines '46'-'49').
Error

Line: 46

              
  @CollectionFeature.Require(KNOWN_ORDER)
  public void testForEachOrder() {
    List<Entry<K, V>> entries = new ArrayList<>();
    multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }
}

            

Reported by PMD.

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

Line: 35

                  extends AbstractContainerTester<Collection<E>, E> {

  // TODO: replace this with an accessor.
  protected Collection<E> collection;

  @Override
  protected Collection<E> actualContents() {
    return collection;
  }

            

Reported by PMD.

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

Line: 57

                /** @return an array of the proper size with {@code null} inserted into the middle element. */
  protected E[] createArrayWithNullElement() {
    E[] array = createSamplesArray();
    array[getNullLocation()] = null;
    return array;
  }

  protected void initCollectionWithNullElement() {
    E[] array = createArrayWithNullElement();

            

Reported by PMD.

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

Line: 63

              
  protected void initCollectionWithNullElement() {
    E[] array = createArrayWithNullElement();
    resetContainer(getSubjectGenerator().create(array));
  }

  /**
   * Equivalent to {@link #expectMissing(Object[]) expectMissing}{@code (null)} except that the call
   * to {@code contains(null)} is permitted to throw a {@code NullPointerException}.

            

Reported by PMD.

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

Line: 74

                 */
  protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

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

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

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

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

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

Line: 56

              
  /** @return an array of the proper size with {@code null} inserted into the middle element. */
  protected E[] createArrayWithNullElement() {
    E[] array = createSamplesArray();
    array[getNullLocation()] = null;
    return array;
  }

  protected void initCollectionWithNullElement() {

            

Reported by PMD.

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

Line: 219

                /** If this collection is backed by an array of its elements in insertion order, returns it. */
  @CheckForNull
  @Nullable
  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: 199

                 * 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: 352

                 * 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 {

  ImmutableCollection() {}

  /** Returns an unmodifiable iterator across the elements in this collection. */
  @Override

            

Reported by PMD.

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

Line: 210

                    }
      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 6 times in this file; the first occurrence is on line 251
Error

Line: 251

                @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 (object not created locally)
Design

Line: 531

                  public Builder<E> addAll(Iterable<? extends E> elements) {
      if (elements instanceof Collection) {
        Collection<?> collection = (Collection<?>) elements;
        getReadyToExpandTo(size + collection.size());
        if (collection instanceof ImmutableCollection) {
          ImmutableCollection<?> immutableCollection = (ImmutableCollection<?>) collection;
          size = immutableCollection.copyIntoArray(contents, size);
          return this;
        }

            

Reported by PMD.

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

Line: 534

                      getReadyToExpandTo(size + collection.size());
        if (collection instanceof ImmutableCollection) {
          ImmutableCollection<?> immutableCollection = (ImmutableCollection<?>) collection;
          size = immutableCollection.copyIntoArray(contents, size);
          return this;
        }
      }
      super.addAll(elements);
      return this;

            

Reported by PMD.

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableBiMap.java
8 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

               * @author Hayward Chan
 */
public abstract class ImmutableBiMap<K, V> extends ForwardingImmutableMap<K, V>
    implements BiMap<K, V> {
  public static <T, K, V> Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap(
      Function<? super T, ? extends K> keyFunction,
      Function<? super T, ? extends V> valueFunction) {
    return CollectCollectors.toImmutableBiMap(keyFunction, valueFunction);
  }

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 63

                  return new RegularImmutableBiMap<K, V>(ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4));
  }

  public static <K, V> ImmutableBiMap<K, V> of(
      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    return new RegularImmutableBiMap<K, V>(ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5));
  }

  public static <K, V> Builder<K, V> builder() {

            

Reported by PMD.

The method 'orderEntriesByValue(Comparator)' is missing an @Override annotation.
Design

Line: 104

                    return this;
    }

    public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) {
      super.orderEntriesByValue(valueComparator);
      return this;
    }

    Builder<K, V> combine(Builder<K, V> other) {

            

Reported by PMD.

The method 'combine(Builder)' is missing an @Override annotation.
Design

Line: 109

                    return this;
    }

    Builder<K, V> combine(Builder<K, V> other) {
      super.combine(other);
      return this;
    }

    @Override

            

Reported by PMD.

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

Line: 117

                  @Override
    public ImmutableBiMap<K, V> build() {
      ImmutableMap<K, V> map = super.build();
      if (map.isEmpty()) {
        return of();
      }
      return new RegularImmutableBiMap<K, V>(super.build());
    }


            

Reported by PMD.

The method 'inverse()' is missing an @Override annotation.
Design

Line: 153

                  super(delegate);
  }

  public abstract ImmutableBiMap<V, K> inverse();

  @Override
  public ImmutableSet<V> values() {
    return inverse().keySet();
  }

            

Reported by PMD.

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

Line: 157

              
  @Override
  public ImmutableSet<V> values() {
    return inverse().keySet();
  }

  public final V forcePut(K key, V value) {
    throw new UnsupportedOperationException();
  }

            

Reported by PMD.

The method 'forcePut(K, V)' is missing an @Override annotation.
Design

Line: 160

                  return inverse().keySet();
  }

  public final V forcePut(K key, V value) {
    throw new UnsupportedOperationException();
  }
}

            

Reported by PMD.

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

Line: 40

              @ElementTypesAreNonnullByDefault
final class FilteredMultimapValues<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractCollection<V> {
  @Weak private final FilteredMultimap<K, V> multimap;

  FilteredMultimapValues(FilteredMultimap<K, V> multimap) {
    this.multimap = checkNotNull(multimap);
  }


            

Reported by PMD.

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

Line: 48

              
  @Override
  public Iterator<V> iterator() {
    return Maps.valueIterator(multimap.entries().iterator());
  }

  @Override
  public boolean contains(@CheckForNull Object o) {
    return multimap.containsValue(o);

            

Reported by PMD.

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

Line: 64

                @Override
  public boolean remove(@CheckForNull Object o) {
    Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
    for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext(); ) {
      Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();
        return true;

            

Reported by PMD.

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

Line: 64

                @Override
  public boolean remove(@CheckForNull Object o) {
    Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
    for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext(); ) {
      Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();
        return true;

            

Reported by PMD.

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

Line: 67

                  for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext(); ) {
      Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();
        return true;
      }
    }
    return false;

            

Reported by PMD.

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

Line: 78

                @Override
  public boolean removeAll(Collection<?> c) {
    return Iterables.removeIf(
        multimap.unfiltered().entries(),
        // explicit <Entry<K, V>> is required to build with JDK6
        Predicates.<Entry<K, V>>and(
            multimap.entryPredicate(), Maps.<V>valuePredicateOnEntries(Predicates.in(c))));
  }


            

Reported by PMD.

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

Line: 87

                @Override
  public boolean retainAll(Collection<?> c) {
    return Iterables.removeIf(
        multimap.unfiltered().entries(),
        // explicit <Entry<K, V>> is required to build with JDK6
        Predicates.<Entry<K, V>>and(
            multimap.entryPredicate(),
            Maps.<V>valuePredicateOnEntries(Predicates.not(Predicates.in(c)))));
  }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entryPredicate' (lines '63'-'73').
Error

Line: 63

              
  @Override
  public boolean remove(@CheckForNull Object o) {
    Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
    for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext(); ) {
      Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();

            

Reported by PMD.

android/guava/src/com/google/common/eventbus/Subscriber.java
8 issues
Avoid throwing raw exception types.
Design

Line: 90

                  try {
      method.invoke(target, checkNotNull(event));
    } catch (IllegalArgumentException e) {
      throw new Error("Method rejected target/argument: " + event, e);
    } catch (IllegalAccessException e) {
      throw new Error("Method became inaccessible: " + event, e);
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 92

                  } catch (IllegalArgumentException e) {
      throw new Error("Method rejected target/argument: " + event, e);
    } catch (IllegalAccessException e) {
      throw new Error("Method became inaccessible: " + event, e);
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();
      }
      throw e;

            

Reported by PMD.

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

Line: 46

                }

  /** The event bus this subscriber belongs to. */
  @Weak private EventBus bus;

  /** The object with the subscriber method. */
  @VisibleForTesting final Object target;

  /** Subscriber method. */

            

Reported by PMD.

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

Line: 46

                }

  /** The event bus this subscriber belongs to. */
  @Weak private EventBus bus;

  /** The object with the subscriber method. */
  @VisibleForTesting final Object target;

  /** Subscriber method. */

            

Reported by PMD.

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

Line: 49

                @Weak private EventBus bus;

  /** The object with the subscriber method. */
  @VisibleForTesting final Object target;

  /** Subscriber method. */
  private final Method method;

  /** Executor to use for dispatching events to this subscriber. */

            

Reported by PMD.

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

Line: 52

                @VisibleForTesting final Object target;

  /** Subscriber method. */
  private final Method method;

  /** Executor to use for dispatching events to this subscriber. */
  private final Executor executor;

  private Subscriber(EventBus bus, Object target, Method method) {

            

Reported by PMD.

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

Line: 55

                private final Method method;

  /** Executor to use for dispatching events to this subscriber. */
  private final Executor executor;

  private Subscriber(EventBus bus, Object target, Method method) {
    this.bus = bus;
    this.target = checkNotNull(target);
    this.method = method;

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 118

                    // Use == so that different equal instances will still receive events.
      // We only guard against the case that the same object is registered
      // multiple times
      return target == that.target && method.equals(that.method);
    }
    return false;
  }

  /**

            

Reported by PMD.

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

Line: 37

               */
@ElementTypesAreNonnullByDefault
abstract class EndpointPairIterator<N> extends AbstractIterator<EndpointPair<N>> {
  private final BaseGraph<N> graph;
  private final Iterator<N> nodeIterator;

  @CheckForNull
  N node = null; // null is safe as an initial value because graphs don't allow null nodes


            

Reported by PMD.

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

Line: 38

              @ElementTypesAreNonnullByDefault
abstract class EndpointPairIterator<N> extends AbstractIterator<EndpointPair<N>> {
  private final BaseGraph<N> graph;
  private final Iterator<N> nodeIterator;

  @CheckForNull
  N node = null; // null is safe as an initial value because graphs don't allow null nodes

  Iterator<N> successorIterator = ImmutableSet.<N>of().iterator();

            

Reported by PMD.

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

Line: 41

                private final Iterator<N> nodeIterator;

  @CheckForNull
  N node = null; // null is safe as an initial value because graphs don't allow null nodes

  Iterator<N> successorIterator = ImmutableSet.<N>of().iterator();

  static <N> EndpointPairIterator<N> of(BaseGraph<N> graph) {
    return graph.isDirected() ? new Directed<N>(graph) : new Undirected<N>(graph);

            

Reported by PMD.

Avoid using redundant field initializer for 'node'
Performance

Line: 41

                private final Iterator<N> nodeIterator;

  @CheckForNull
  N node = null; // null is safe as an initial value because graphs don't allow null nodes

  Iterator<N> successorIterator = ImmutableSet.<N>of().iterator();

  static <N> EndpointPairIterator<N> of(BaseGraph<N> graph) {
    return graph.isDirected() ? new Directed<N>(graph) : new Undirected<N>(graph);

            

Reported by PMD.

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

Line: 43

                @CheckForNull
  N node = null; // null is safe as an initial value because graphs don't allow null nodes

  Iterator<N> successorIterator = ImmutableSet.<N>of().iterator();

  static <N> EndpointPairIterator<N> of(BaseGraph<N> graph) {
    return graph.isDirected() ? new Directed<N>(graph) : new Undirected<N>(graph);
  }


            

Reported by PMD.

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

Line: 64

                    return false;
    }
    node = nodeIterator.next();
    successorIterator = graph.successors(node).iterator();
    return true;
  }

  /**
   * If the graph is directed, each ordered [source, target] pair will be visited once if there is

            

Reported by PMD.

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

Line: 120

                 */
  private static final class Undirected<N> extends EndpointPairIterator<N> {
    // It's a little weird that we add `null` to this set, but it makes for slightly simpler code.
    @CheckForNull private Set<@Nullable N> visitedNodes;

    private Undirected(BaseGraph<N> graph) {
      super(graph);
      this.visitedNodes = Sets.newHashSetWithExpectedSize(graph.nodes().size() + 1);
    }

            

Reported by PMD.

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

Line: 146

                      // Add to visited set *after* processing neighbors so we still include self-loops.
        visitedNodes.add(node);
        if (!advance()) {
          visitedNodes = null;
          return endOfData();
        }
      }
    }
  }

            

Reported by PMD.

android/guava/src/com/google/common/cache/LongAdder.java
8 issues
This class has too many methods, consider refactoring it.
Design

Line: 44

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class LongAdder extends Striped64 implements Serializable, LongAddable {
  private static final long serialVersionUID = 7249069246863182397L;

  /** Version of plus for use in retryUpdate */
  @Override
  final long fn(long v, long x) {

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 68

                  int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 70

                  int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);
    }

            

Reported by PMD.

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

Line: 191

                private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    s.defaultReadObject();
    busy = 0;
    cells = null;
    base = s.readLong();
  }
}

            

Reported by PMD.

Use one line for each declaration, it enhances code readability.
Design

Line: 64

                @Override
  public void add(long x) {
    Cell[] as;
    long b, v;
    int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'as' (lines '68'-'76').
Error

Line: 68

                  int[] hc;
    Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null

            

Reported by PMD.

Found 'DD'-anomaly for variable 'uncontended' (lines '69'-'70').
Error

Line: 69

                  Cell a;
    int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'uncontended' (lines '70'-'76').
Error

Line: 70

                  int n;
    if ((as = cells) != null || !casBase(b = base, b + x)) {
      boolean uncontended = true;
      if ((hc = threadHashCode.get()) == null
          || as == null
          || (n = as.length) < 1
          || (a = as[(n - 1) & hc[0]]) == null
          || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);
    }

            

Reported by PMD.

android/guava/src/com/google/common/graph/ImmutableNetwork.java
8 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 87

                  for (N node : network.nodes()) {
      nodeConnections.put(node, connectionsOf(network, node));
    }
    return nodeConnections.build();
  }

  private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
    // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
    // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the

            

Reported by PMD.

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

Line: 96

                  // input edges are sorted.
    ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
    for (E edge : network.edges()) {
      edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
    }
    return edgeToReferenceNode.build();
  }

  private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) {

            

Reported by PMD.

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

Line: 98

                  for (E edge : network.edges()) {
      edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
    }
    return edgeToReferenceNode.build();
  }

  private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) {
    if (network.isDirected()) {
      Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network));

            

Reported by PMD.

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

Line: 105

                  if (network.isDirected()) {
      Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network));
      Map<E, N> outEdgeMap = Maps.asMap(network.outEdges(node), targetNodeFn(network));
      int selfLoopCount = network.edgesConnecting(node, node).size();
      return network.allowsParallelEdges()
          ? DirectedMultiNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount)
          : DirectedNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount);
    } else {
      Map<E, N> incidentEdgeMap =

            

Reported by PMD.

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

Line: 122

                  return new Function<E, N>() {
      @Override
      public N apply(E edge) {
        return network.incidentNodes(edge).source();
      }
    };
  }

  private static <N, E> Function<E, N> targetNodeFn(final Network<N, E> network) {

            

Reported by PMD.

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

Line: 131

                  return new Function<E, N>() {
      @Override
      public N apply(E edge) {
        return network.incidentNodes(edge).target();
      }
    };
  }

  private static <N, E> Function<E, N> adjacentNodeFn(final Network<N, E> network, final N node) {

            

Reported by PMD.

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

Line: 140

                  return new Function<E, N>() {
      @Override
      public N apply(E edge) {
        return network.incidentNodes(edge).adjacentNode(node);
      }
    };
  }

  /**

            

Reported by PMD.

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

Line: 170

                 */
  public static class Builder<N, E> {

    private final MutableNetwork<N, E> mutableNetwork;

    Builder(NetworkBuilder<N, E> networkBuilder) {
      this.mutableNetwork = networkBuilder.build();
    }


            

Reported by PMD.