The following issues were found

guava/src/com/google/common/collect/ImmutableSortedMultiset.java
23 issues
Avoid reassigning parameters such as 'elements'
Design

Line: 258

                 * @throws NullPointerException if {@code comparator} or any of {@code elements} is null
   */
  public static <E> ImmutableSortedMultiset<E> copyOf(
      Comparator<? super E> comparator, Iterable<? extends E> elements) {
    if (elements instanceof ImmutableSortedMultiset) {
      @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
      ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 55

               */
@GwtIncompatible // hasn't been tested yet
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultisetFauxverideShim<E>
    implements SortedMultiset<E> {
  // TODO(lowasser): GWT compatibility

  /**
   * Returns a {@code Collector} that accumulates the input elements into a new {@code

            

Reported by PMD.

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

Line: 56

              @GwtIncompatible // hasn't been tested yet
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultisetFauxverideShim<E>
    implements SortedMultiset<E> {
  // TODO(lowasser): GWT compatibility

  /**
   * Returns a {@code Collector} that accumulates the input elements into a new {@code
   * ImmutableMultiset}. Elements are sorted by the specified comparator.

            

Reported by PMD.

The String literal 'unchecked' appears 6 times in this file; the first occurrence is on line 108
Error

Line: 108

                 *
   * <p><b>Performance note:</b> the instance returned is a singleton.
   */
  @SuppressWarnings("unchecked")
  public static <E> ImmutableSortedMultiset<E> of() {
    return (ImmutableSortedMultiset) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET;
  }

  /** Returns an immutable sorted multiset containing a single element. */

            

Reported by PMD.

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

Line: 262

                  if (elements instanceof ImmutableSortedMultiset) {
      @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
      ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }

            

Reported by PMD.

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

Line: 263

                    @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
      ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }
      }

            

Reported by PMD.

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

Line: 264

                    ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }
      }
    }

            

Reported by PMD.

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

Line: 264

                    ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
      if (comparator.equals(multiset.comparator())) {
        if (multiset.isPartialView()) {
          return copyOfSortedEntries(comparator, multiset.entrySet().asList());
        } else {
          return multiset;
        }
      }
    }

            

Reported by PMD.

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

Line: 273

                  elements = Lists.newArrayList(elements); // defensive copy
    TreeMultiset<E> sortedCopy = TreeMultiset.create(checkNotNull(comparator));
    Iterables.addAll(sortedCopy, elements);
    return copyOfSortedEntries(comparator, sortedCopy.entrySet());
  }

  /**
   * Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by
   * the same {@code Comparator}. That behavior differs from {@link #copyOf(Iterable)}, which always

            

Reported by PMD.

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

Line: 317

              
  @SuppressWarnings("unchecked")
  static <E> ImmutableSortedMultiset<E> emptyMultiset(Comparator<? super E> comparator) {
    if (Ordering.natural().equals(comparator)) {
      return (ImmutableSortedMultiset<E>) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET;
    } else {
      return new RegularImmutableSortedMultiset<E>(comparator);
    }
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/SupplementalMonitorTest.java
23 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 39

              
public class SupplementalMonitorTest extends TestCase {

  public void testLeaveWithoutEnterThrowsIMSE() {
    Monitor monitor = new Monitor();
    try {
      monitor.leave();
      fail("expected IllegalMonitorStateException");
    } catch (IllegalMonitorStateException expected) {

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 43

                  Monitor monitor = new Monitor();
    try {
      monitor.leave();
      fail("expected IllegalMonitorStateException");
    } catch (IllegalMonitorStateException expected) {
    }
  }

  public void testGetWaitQueueLengthWithWrongMonitorThrowsIMSE() {

            

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

                  }
  }

  public void testGetWaitQueueLengthWithWrongMonitorThrowsIMSE() {
    Monitor monitor1 = new Monitor();
    Monitor monitor2 = new Monitor();
    FlagGuard guard = new FlagGuard(monitor2);
    try {
      monitor1.getWaitQueueLength(guard);

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 54

                  FlagGuard guard = new FlagGuard(monitor2);
    try {
      monitor1.getWaitQueueLength(guard);
      fail("expected IllegalMonitorStateException");
    } catch (IllegalMonitorStateException expected) {
    }
  }

  public void testHasWaitersWithWrongMonitorThrowsIMSE() {

            

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

                  }
  }

  public void testHasWaitersWithWrongMonitorThrowsIMSE() {
    Monitor monitor1 = new Monitor();
    Monitor monitor2 = new Monitor();
    FlagGuard guard = new FlagGuard(monitor2);
    try {
      monitor1.hasWaiters(guard);

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 65

                  FlagGuard guard = new FlagGuard(monitor2);
    try {
      monitor1.hasWaiters(guard);
      fail("expected IllegalMonitorStateException");
    } catch (IllegalMonitorStateException expected) {
    }
  }

  public void testNullMonitorInGuardConstructorThrowsNPE() {

            

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

                  }
  }

  public void testNullMonitorInGuardConstructorThrowsNPE() {
    try {
      new FlagGuard(null);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 73

                public void testNullMonitorInGuardConstructorThrowsNPE() {
    try {
      new FlagGuard(null);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }

  public void testIsFair() {

            

Reported by PMD.

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

Line: 74

                  try {
      new FlagGuard(null);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }

  public void testIsFair() {
    assertTrue(new Monitor(true).isFair());

            

Reported by PMD.

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

Line: 74

                  try {
      new FlagGuard(null);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }

  public void testIsFair() {
    assertTrue(new Monitor(true).isFair());

            

Reported by PMD.

android/guava/src/com/google/common/base/MoreObjects.java
23 issues
Avoid throwing null pointer exceptions.
Design

Line: 85

                  if (second != null) {
      return second;
    }
    throw new NullPointerException("Both parameters are null");
  }

  /**
   * Creates an instance of {@link ToStringHelper}.
   *

            

Reported by PMD.

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

Line: 129

                 * @since 18.0 (since 2.0 as {@code Objects.toStringHelper()}).
   */
  public static ToStringHelper toStringHelper(Object self) {
    return new ToStringHelper(self.getClass().getSimpleName());
  }

  /**
   * Creates an instance of {@link ToStringHelper} in the same manner as {@link
   * #toStringHelper(Object)}, but using the simple name of {@code clazz} instead of using an

            

Reported by PMD.

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

Line: 164

                 * @author Jason Lee
   * @since 18.0 (since 2.0 as {@code Objects.ToStringHelper}).
   */
  public static final class ToStringHelper {
    private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

            

Reported by PMD.

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

Line: 165

                 * @since 18.0 (since 2.0 as {@code Objects.ToStringHelper}).
   */
  public static final class ToStringHelper {
    private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;


            

Reported by PMD.

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

Line: 166

                 */
  public static final class ToStringHelper {
    private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */

            

Reported by PMD.

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

Line: 167

                public static final class ToStringHelper {
    private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */
    private ToStringHelper(String className) {

            

Reported by PMD.

Field omitNullValues has the same name as a method
Error

Line: 168

                  private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */
    private ToStringHelper(String className) {
      this.className = checkNotNull(className);

            

Reported by PMD.

Avoid using redundant field initializer for 'omitNullValues'
Performance

Line: 168

                  private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */
    private ToStringHelper(String className) {
      this.className = checkNotNull(className);

            

Reported by PMD.

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

Line: 168

                  private final String className;
    private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */
    private ToStringHelper(String className) {
      this.className = checkNotNull(className);

            

Reported by PMD.

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

Line: 169

                  private final ValueHolder holderHead = new ValueHolder();
    private ValueHolder holderTail = holderHead;
    private boolean omitNullValues = false;
    private boolean omitEmptyValues = false;

    /** Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */
    private ToStringHelper(String className) {
      this.className = checkNotNull(className);
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/math/QuantilesAlgorithmTest.java
23 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

                    Sets.difference(
          ImmutableSet.copyOf(QuantilesAlgorithm.values()), ImmutableSet.of(REFERENCE_ALGORITHM));

  private double[] dataset;

  @Override
  protected void setUp() {
    dataset = new double[DATASET_SIZE];
    for (int i = 0; i < DATASET_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: 45

              
  private double[] dataset;

  @Override
  protected void setUp() {
    dataset = new double[DATASET_SIZE];
    for (int i = 0; i < DATASET_SIZE; i++) {
      dataset[i] = RNG.nextDouble();
    }

            

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

                  }
  }

  public void testSingleQuantile_median() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(1, 2, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(1, 2, dataset.clone()))
          .isWithin(ALLOWED_ERROR)

            

Reported by PMD.

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

Line: 56

                public void testSingleQuantile_median() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(1, 2, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(1, 2, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

Reported by PMD.

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

Line: 56

                public void testSingleQuantile_median() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(1, 2, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(1, 2, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

Reported by PMD.

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

Line: 56

                public void testSingleQuantile_median() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(1, 2, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(1, 2, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

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

                  }
  }

  public void testSingleQuantile_percentile99() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(99, 100, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(99, 100, dataset.clone()))
          .isWithin(ALLOWED_ERROR)

            

Reported by PMD.

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

Line: 66

                public void testSingleQuantile_percentile99() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(99, 100, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(99, 100, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

Reported by PMD.

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

Line: 66

                public void testSingleQuantile_percentile99() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(99, 100, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(99, 100, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

Reported by PMD.

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

Line: 66

                public void testSingleQuantile_percentile99() {
    double referenceValue = REFERENCE_ALGORITHM.singleQuantile(99, 100, dataset.clone());
    for (QuantilesAlgorithm algorithm : NON_REFERENCE_ALGORITHMS) {
      assertWithMessage("Mismatch between %s and %s", algorithm, REFERENCE_ALGORITHM)
          .that(algorithm.singleQuantile(99, 100, dataset.clone()))
          .isWithin(ALLOWED_ERROR)
          .of(referenceValue);
    }
  }

            

Reported by PMD.

android/guava/src/com/google/common/graph/StandardNetwork.java
23 issues
This class has too many methods, consider refactoring it.
Design

Line: 52

               * @param <E> Edge parameter type
 */
@ElementTypesAreNonnullByDefault
class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

            

Reported by PMD.

Field isDirected has the same name as a method
Error

Line: 53

               */
@ElementTypesAreNonnullByDefault
class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;


            

Reported by PMD.

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

Line: 53

               */
@ElementTypesAreNonnullByDefault
class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;


            

Reported by PMD.

Field allowsParallelEdges has the same name as a method
Error

Line: 54

              @ElementTypesAreNonnullByDefault
class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;

            

Reported by PMD.

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

Line: 54

              @ElementTypesAreNonnullByDefault
class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;

            

Reported by PMD.

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

Line: 55

              class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;


            

Reported by PMD.

Field allowsSelfLoops has the same name as a method
Error

Line: 55

              class StandardNetwork<N, E> extends AbstractNetwork<N, E> {
  private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;


            

Reported by PMD.

Field nodeOrder has the same name as a method
Error

Line: 56

                private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;

  // We could make this a Map<E, EndpointPair<N>>. It would make incidentNodes(edge) slightly

            

Reported by PMD.

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

Line: 56

                private final boolean isDirected;
  private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;

  // We could make this a Map<E, EndpointPair<N>>. It would make incidentNodes(edge) slightly

            

Reported by PMD.

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

Line: 57

                private final boolean allowsParallelEdges;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;
  private final ElementOrder<E> edgeOrder;

  final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections;

  // We could make this a Map<E, EndpointPair<N>>. It would make incidentNodes(edge) slightly
  // faster, but also make Networks consume 5 to 20+% (increasing with average degree) more memory.

            

Reported by PMD.

android/guava/src/com/google/common/collect/AbstractMultimap.java
23 issues
This class has too many methods, consider refactoring it.
Design

Line: 42

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class AbstractMultimap<K extends @Nullable Object, V extends @Nullable Object>
    implements Multimap<K, V> {
  @Override
  public boolean isEmpty() {
    return size() == 0;
  }


            

Reported by PMD.

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

Line: 50

              
  @Override
  public boolean containsValue(@CheckForNull Object value) {
    for (Collection<V> collection : asMap().values()) {
      if (collection.contains(value)) {
        return true;
      }
    }


            

Reported by PMD.

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

Line: 61

              
  @Override
  public boolean containsEntry(@CheckForNull Object key, @CheckForNull Object value) {
    Collection<V> collection = asMap().get(key);
    return collection != null && collection.contains(value);
  }

  @CanIgnoreReturnValue
  @Override

            

Reported by PMD.

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

Line: 62

                @Override
  public boolean containsEntry(@CheckForNull Object key, @CheckForNull Object value) {
    Collection<V> collection = asMap().get(key);
    return collection != null && collection.contains(value);
  }

  @CanIgnoreReturnValue
  @Override
  public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {

            

Reported by PMD.

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

Line: 68

                @CanIgnoreReturnValue
  @Override
  public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {
    Collection<V> collection = asMap().get(key);
    return collection != null && collection.remove(value);
  }

  @CanIgnoreReturnValue
  @Override

            

Reported by PMD.

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

Line: 69

                @Override
  public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {
    Collection<V> collection = asMap().get(key);
    return collection != null && collection.remove(value);
  }

  @CanIgnoreReturnValue
  @Override
  public boolean put(@ParametricNullness K key, @ParametricNullness V value) {

            

Reported by PMD.

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

Line: 75

                @CanIgnoreReturnValue
  @Override
  public boolean put(@ParametricNullness K key, @ParametricNullness V value) {
    return get(key).add(value);
  }

  @CanIgnoreReturnValue
  @Override
  public boolean putAll(@ParametricNullness K key, Iterable<? extends V> values) {

            

Reported by PMD.

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

Line: 86

                  // and we only call get(key) if values is nonempty
    if (values instanceof Collection) {
      Collection<? extends V> valueCollection = (Collection<? extends V>) values;
      return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
    } else {
      Iterator<? extends V> valueItr = values.iterator();
      return valueItr.hasNext() && Iterators.addAll(get(key), valueItr);
    }
  }

            

Reported by PMD.

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

Line: 86

                  // and we only call get(key) if values is nonempty
    if (values instanceof Collection) {
      Collection<? extends V> valueCollection = (Collection<? extends V>) values;
      return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
    } else {
      Iterator<? extends V> valueItr = values.iterator();
      return valueItr.hasNext() && Iterators.addAll(get(key), valueItr);
    }
  }

            

Reported by PMD.

Field entries has the same name as a method
Error

Line: 112

                  return result;
  }

  @LazyInit @CheckForNull private transient Collection<Entry<K, V>> entries;

  @Override
  public Collection<Entry<K, V>> entries() {
    Collection<Entry<K, V>> result = entries;
    return (result == null) ? entries = createEntries() : result;

            

Reported by PMD.

android/guava/src/com/google/common/collect/ImmutableSortedSet.java
23 issues
Possible God Class (WMC=54, ATFD=20, TCC=8.462%)
Design

Line: 62

              @GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E>
    implements NavigableSet<E>, SortedIterable<E> {
  static <E> RegularImmutableSortedSet<E> emptySet(Comparator<? super E> comparator) {
    if (Ordering.natural().equals(comparator)) {
      return (RegularImmutableSortedSet<E>) RegularImmutableSortedSet.NATURAL_EMPTY_SET;
    } else {

            

Reported by PMD.

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

Line: 63

              @SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E>
    implements NavigableSet<E>, SortedIterable<E> {
  static <E> RegularImmutableSortedSet<E> emptySet(Comparator<? super E> comparator) {
    if (Ordering.natural().equals(comparator)) {
      return (RegularImmutableSortedSet<E>) RegularImmutableSortedSet.NATURAL_EMPTY_SET;
    } else {
      return new RegularImmutableSortedSet<E>(ImmutableList.<E>of(), comparator);

            

Reported by PMD.

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

Line: 65

              public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E>
    implements NavigableSet<E>, SortedIterable<E> {
  static <E> RegularImmutableSortedSet<E> emptySet(Comparator<? super E> comparator) {
    if (Ordering.natural().equals(comparator)) {
      return (RegularImmutableSortedSet<E>) RegularImmutableSortedSet.NATURAL_EMPTY_SET;
    } else {
      return new RegularImmutableSortedSet<E>(ImmutableList.<E>of(), comparator);
    }
  }

            

Reported by PMD.

The String literal 'unchecked' appears 13 times in this file; the first occurrence is on line 93
Error

Line: 93

                 *
   * @throws NullPointerException if any element is null
   */
  @SuppressWarnings("unchecked")
  public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2) {
    return construct(Ordering.natural(), 2, e1, e2);
  }

  /**

            

Reported by PMD.

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

Line: 282

                  if (hasSameComparator && (elements instanceof ImmutableSortedSet)) {
      @SuppressWarnings("unchecked")
      ImmutableSortedSet<E> original = (ImmutableSortedSet<E>) elements;
      if (!original.isPartialView()) {
        return original;
      }
    }
    @SuppressWarnings("unchecked") // elements only contains E's; it's safe.
    E[] array = (E[]) Iterables.toArray(elements);

            

Reported by PMD.

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

Line: 328

                public static <E> ImmutableSortedSet<E> copyOfSorted(SortedSet<E> sortedSet) {
    Comparator<? super E> comparator = SortedIterables.comparator(sortedSet);
    ImmutableList<E> list = ImmutableList.copyOf(sortedSet);
    if (list.isEmpty()) {
      return emptySet(comparator);
    } else {
      return new RegularImmutableSortedSet<E>(list, comparator);
    }
  }

            

Reported by PMD.

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

Line: 506

                    @SuppressWarnings("unchecked") // we're careful to put only E's in here
      E[] contentsArray = (E[]) contents;
      ImmutableSortedSet<E> result = construct(comparator, size, contentsArray);
      this.size = result.size(); // we eliminated duplicates in-place in contentsArray
      this.forceCopy = true;
      return result;
    }
  }


            

Reported by PMD.

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

Line: 522

                  // that are spec'd to throw CCE and NPE should call this.
    @SuppressWarnings({"unchecked", "nullness"})
    Comparator<@Nullable Object> unsafeComparator = (Comparator<@Nullable Object>) comparator;
    return unsafeComparator.compare(a, b);
  }

  final transient Comparator<? super E> comparator;

  ImmutableSortedSet(Comparator<? super E> comparator) {

            

Reported by PMD.

Field comparator has the same name as a method
Error

Line: 525

                  return unsafeComparator.compare(a, b);
  }

  final transient Comparator<? super E> comparator;

  ImmutableSortedSet(Comparator<? super E> comparator) {
    this.comparator = comparator;
  }


            

Reported by PMD.

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

Line: 630

                @Override
  @CheckForNull
  public E lower(E e) {
    return Iterators.getNext(headSet(e, false).descendingIterator(), null);
  }

  /** @since 12.0 */
  @Override
  @CheckForNull

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/SequentialExecutor.java
23 issues
Logger calls should be surrounded by log level guards.
Design

Line: 237

                        try {
            task.run();
          } catch (RuntimeException e) {
            log.log(Level.SEVERE, "Exception while executing runnable " + task, e);
          } finally {
            task = null;
          }
        }
      } finally {

            

Reported by PMD.

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

Line: 66

                }

  /** Underlying executor that all submitted Runnable objects are run on. */
  private final Executor executor;

  @GuardedBy("queue")
  private final Deque<Runnable> queue = new ArrayDeque<>();

  /** see {@link WorkerRunningState} */

            

Reported by PMD.

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

Line: 69

                private final Executor executor;

  @GuardedBy("queue")
  private final Deque<Runnable> queue = new ArrayDeque<>();

  /** see {@link WorkerRunningState} */
  @GuardedBy("queue")
  private WorkerRunningState workerRunningState = IDLE;


            

Reported by PMD.

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

Line: 73

              
  /** see {@link WorkerRunningState} */
  @GuardedBy("queue")
  private WorkerRunningState workerRunningState = IDLE;

  /**
   * This counter prevents an ABA issue where a thread may successfully schedule the worker, the
   * worker runs and exhausts the queue, another thread enqueues a task and fails to schedule the
   * worker, and then the first thread's call to delegate.execute() returns. Without this counter,

            

Reported by PMD.

Avoid using redundant field initializer for 'workerRunCount'
Performance

Line: 83

                 * scheduled again for future submissions.
   */
  @GuardedBy("queue")
  private long workerRunCount = 0;

  @RetainedWith private final QueueWorker worker = new QueueWorker();

  /** Use {@link MoreExecutors#newSequentialExecutor} */
  SequentialExecutor(Executor executor) {

            

Reported by PMD.

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

Line: 83

                 * scheduled again for future submissions.
   */
  @GuardedBy("queue")
  private long workerRunCount = 0;

  @RetainedWith private final QueueWorker worker = new QueueWorker();

  /** Use {@link MoreExecutors#newSequentialExecutor} */
  SequentialExecutor(Executor executor) {

            

Reported by PMD.

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

Line: 85

                @GuardedBy("queue")
  private long workerRunCount = 0;

  @RetainedWith private final QueueWorker worker = new QueueWorker();

  /** Use {@link MoreExecutors#newSequentialExecutor} */
  SequentialExecutor(Executor executor) {
    this.executor = Preconditions.checkNotNull(executor);
  }

            

Reported by PMD.

The method 'execute(Runnable)' has a cyclomatic complexity of 10.
Design

Line: 99

                 * execution of tasks will stop until a call to this method is made.
   */
  @Override
  public void execute(final Runnable task) {
    checkNotNull(task);
    final Runnable submittedTask;
    final long oldRunCount;
    synchronized (queue) {
      // If the worker is already running (or execute() on the delegate returned successfully, and

            

Reported by PMD.

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

Line: 137

              
    try {
      executor.execute(worker);
    } catch (RuntimeException | Error t) {
      synchronized (queue) {
        boolean removed =
            (workerRunningState == IDLE || workerRunningState == QUEUING)
                && queue.removeLastOccurrence(submittedTask);
        // If the delegate is directExecutor(), the submitted runnable could have thrown a REE. But

            

Reported by PMD.

An instanceof check is being performed on the caught exception. Create a separate catch clause for this exception type.
Error

Line: 144

                              && queue.removeLastOccurrence(submittedTask);
        // If the delegate is directExecutor(), the submitted runnable could have thrown a REE. But
        // that's handled by the log check that catches RuntimeExceptions in the queue worker.
        if (!(t instanceof RejectedExecutionException) || removed) {
          throw t;
        }
      }
      return;
    }

            

Reported by PMD.

android/guava/src/com/google/common/collect/ArrayTable.java
23 issues
Possible God Class (WMC=52, ATFD=12, TCC=14.603%)
Design

Line: 94

              @Beta
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class ArrayTable<R, C, V> extends AbstractTable<R, C, @Nullable V>
    implements Serializable {

  /**
   * Creates an {@code ArrayTable} filled with {@code null}.
   *

            

Reported by PMD.

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

Line: 95

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class ArrayTable<R, C, V> extends AbstractTable<R, C, @Nullable V>
    implements Serializable {

  /**
   * Creates an {@code ArrayTable} filled with {@code null}.
   *
   * @param rowKeys row keys that may be stored in the generated table

            

Reported by PMD.

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

Line: 141

                      : new ArrayTable<R, C, V>(table);
  }

  private final ImmutableList<R> rowList;
  private final ImmutableList<C> columnList;

  // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex?
  private final ImmutableMap<R, Integer> rowKeyToIndex;
  private final ImmutableMap<C, Integer> columnKeyToIndex;

            

Reported by PMD.

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

Line: 142

                }

  private final ImmutableList<R> rowList;
  private final ImmutableList<C> columnList;

  // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex?
  private final ImmutableMap<R, Integer> rowKeyToIndex;
  private final ImmutableMap<C, Integer> columnKeyToIndex;
  private final @Nullable V[][] array;

            

Reported by PMD.

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

Line: 145

                private final ImmutableList<C> columnList;

  // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex?
  private final ImmutableMap<R, Integer> rowKeyToIndex;
  private final ImmutableMap<C, Integer> columnKeyToIndex;
  private final @Nullable V[][] array;

  private ArrayTable(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) {
    this.rowList = ImmutableList.copyOf(rowKeys);

            

Reported by PMD.

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

Line: 146

              
  // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex?
  private final ImmutableMap<R, Integer> rowKeyToIndex;
  private final ImmutableMap<C, Integer> columnKeyToIndex;
  private final @Nullable V[][] array;

  private ArrayTable(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) {
    this.rowList = ImmutableList.copyOf(rowKeys);
    this.columnList = ImmutableList.copyOf(columnKeys);

            

Reported by PMD.

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

Line: 147

                // TODO(jlevy): Add getters returning rowKeyToIndex and columnKeyToIndex?
  private final ImmutableMap<R, Integer> rowKeyToIndex;
  private final ImmutableMap<C, Integer> columnKeyToIndex;
  private final @Nullable V[][] array;

  private ArrayTable(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) {
    this.rowList = ImmutableList.copyOf(rowKeys);
    this.columnList = ImmutableList.copyOf(columnKeys);
    checkArgument(rowList.isEmpty() == columnList.isEmpty());

            

Reported by PMD.

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

Line: 192

              
  private abstract static class ArrayMap<K, V extends @Nullable Object>
      extends IteratorBasedAbstractMap<K, V> {
    private final ImmutableMap<K, Integer> keyIndex;

    private ArrayMap(ImmutableMap<K, Integer> keyIndex) {
      this.keyIndex = keyIndex;
    }


            

Reported by PMD.

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

Line: 204

                  }

    K getKey(int index) {
      return keyIndex.keySet().asList().get(index);
    }

    abstract String getKeyRole();

    @ParametricNullness

            

Reported by PMD.

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

Line: 204

                  }

    K getKey(int index) {
      return keyIndex.keySet().asList().get(index);
    }

    abstract String getKeyRole();

    @ParametricNullness

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/ThreadFactoryBuilder.java
23 issues
Avoid using redundant field initializer for 'nameFormat'
Performance

Line: 52

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;


            

Reported by PMD.

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

Line: 52

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;


            

Reported by PMD.

Avoid using redundant field initializer for 'daemon'
Performance

Line: 53

              @ElementTypesAreNonnullByDefault
public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */

            

Reported by PMD.

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

Line: 53

              @ElementTypesAreNonnullByDefault
public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */

            

Reported by PMD.

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

Line: 54

              public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}

            

Reported by PMD.

Avoid using redundant field initializer for 'priority'
Performance

Line: 54

              public final class ThreadFactoryBuilder {
  @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}

            

Reported by PMD.

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

Line: 55

                @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}


            

Reported by PMD.

Avoid using redundant field initializer for 'uncaughtExceptionHandler'
Performance

Line: 55

                @CheckForNull private String nameFormat = null;
  @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}


            

Reported by PMD.

Avoid using redundant field initializer for 'backingThreadFactory'
Performance

Line: 56

                @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}

  /**

            

Reported by PMD.

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

Line: 56

                @CheckForNull private Boolean daemon = null;
  @CheckForNull private Integer priority = null;
  @CheckForNull private UncaughtExceptionHandler uncaughtExceptionHandler = null;
  @CheckForNull private ThreadFactory backingThreadFactory = null;

  /** Creates a new {@link ThreadFactory} builder. */
  public ThreadFactoryBuilder() {}

  /**

            

Reported by PMD.