The following issues were found

guava/src/com/google/common/math/Stats.java
37 issues
This class has too many methods, consider refactoring it.
Design

Line: 68

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;

            

Reported by PMD.

Possible God Class (WMC=50, ATFD=29, TCC=21.720%)
Design

Line: 68

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;

            

Reported by PMD.

Field count has the same name as a method
Error

Line: 70

              @ElementTypesAreNonnullByDefault
public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;


            

Reported by PMD.

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

Line: 70

              @ElementTypesAreNonnullByDefault
public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;


            

Reported by PMD.

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

Line: 71

              public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**

            

Reported by PMD.

Field mean has the same name as a method
Error

Line: 71

              public final class Stats implements Serializable {

  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**

            

Reported by PMD.

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

Line: 72

              
  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**
   * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}.

            

Reported by PMD.

Field sumOfSquaresOfDeltas has the same name as a method
Error

Line: 72

              
  private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**
   * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}.

            

Reported by PMD.

Field min has the same name as a method
Error

Line: 73

                private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**
   * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}.
   *

            

Reported by PMD.

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

Line: 73

                private final long count;
  private final double mean;
  private final double sumOfSquaresOfDeltas;
  private final double min;
  private final double max;

  /**
   * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}.
   *

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/Uninterruptibles.java
37 issues
Possible God Class (WMC=64, ATFD=11, TCC=0.000%)
Design

Line: 50

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Uninterruptibles {

  // Implementation Note: As of 3-7-11, the logic for each blocking/timeout
  // methods is identical, save for method being invoked.

  /** Invokes {@code latch.}{@link CountDownLatch#await() await()} uninterruptibly. */

            

Reported by PMD.

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

Line: 50

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Uninterruptibles {

  // Implementation Note: As of 3-7-11, the logic for each blocking/timeout
  // methods is identical, save for method being invoked.

  /** Invokes {@code latch.}{@link CountDownLatch#await() await()} uninterruptibly. */

            

Reported by PMD.

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

Line: 70

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

The String literal 'GoodTime' appears 9 times in this file; the first occurrence is on line 94
Error

Line: 94

                 */
  @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict.
  @GwtIncompatible // concurrency
  @SuppressWarnings("GoodTime") // should accept a java.time.Duration
  public static boolean awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit) {
    boolean interrupted = false;
    try {
      long remainingNanos = unit.toNanos(timeout);
      long end = System.nanoTime() + remainingNanos;

            

Reported by PMD.

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

Line: 112

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 153

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /** Invokes {@code toJoin.}{@link Thread#join() join()} uninterruptibly. */

            

Reported by PMD.

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

Line: 173

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 214

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 251

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 324

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /** Invokes {@code queue.}{@link BlockingQueue#take() take()} uninterruptibly. */

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/Futures.java
37 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 15

               * the License.
 */

package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

            

Reported by PMD.

Avoid really long classes.
Design

Line: 79

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Futures extends GwtFuturesCatchingSpecialization {

  // A note on memory visibility.
  // Many of the utilities in this class (transform, withFallback, withTimeout, asList, combine)
  // have two requirements that significantly complicate their design.
  // 1. Cancellation should propagate from the returned future to the input future(s).

            

Reported by PMD.

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

Line: 79

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Futures extends GwtFuturesCatchingSpecialization {

  // A note on memory visibility.
  // Many of the utilities in this class (transform, withFallback, withTimeout, asList, combine)
  // have two requirements that significantly complicate their design.
  // 1. Cancellation should propagate from the returned future to the input future(s).

            

Reported by PMD.

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

Line: 137

                    @ParametricNullness V value) {
    if (value == null) {
      // This cast is safe because null is assignable to V for all V (i.e. it is bivariant)
      @SuppressWarnings("unchecked")
      ListenableFuture<V> typedNull = (ListenableFuture<V>) ImmediateFuture.NULL;
      return typedNull;
    }
    return new ImmediateFuture<>(value);
  }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 551

                    private O applyTransformation(I input) throws ExecutionException {
        try {
          return function.apply(input);
        } catch (Throwable t) {
          throw new ExecutionException(t);
        }
      }
    };
  }

            

Reported by PMD.

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

Line: 699

                @CanIgnoreReturnValue // TODO(cpovirk): Consider removing, especially if we provide run(Runnable)
  @GwtCompatible
  public static final class FutureCombiner<V extends @Nullable Object> {
    private final boolean allMustSucceed;
    private final ImmutableList<ListenableFuture<? extends V>> futures;

    private FutureCombiner(
        boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures) {
      this.allMustSucceed = allMustSucceed;

            

Reported by PMD.

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

Line: 700

                @GwtCompatible
  public static final class FutureCombiner<V extends @Nullable Object> {
    private final boolean allMustSucceed;
    private final ImmutableList<ListenableFuture<? extends V>> futures;

    private FutureCombiner(
        boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures) {
      this.allMustSucceed = allMustSucceed;
      this.futures = futures;

            

Reported by PMD.

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

Line: 793

                /** A wrapped future that does not propagate cancellation to its delegate. */
  private static final class NonCancellationPropagatingFuture<V extends @Nullable Object>
      extends AbstractFuture.TrustedFuture<V> implements Runnable {
    @CheckForNull private ListenableFuture<V> delegate;

    NonCancellationPropagatingFuture(final ListenableFuture<V> delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

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

Line: 821

              
    @Override
    protected void afterDone() {
      delegate = null;
    }
  }

  /**
   * Creates a new {@code ListenableFuture} whose value is a list containing the values of all its

            

Reported by PMD.

guava/src/com/google/common/collect/AbstractBiMap.java
37 issues
Overridable method 'setDelegates' called during object construction
Error

Line: 60

              
  /** Package-private constructor for creating a map-backed bimap. */
  AbstractBiMap(Map<K, V> forward, Map<V, K> backward) {
    setDelegates(forward, backward);
  }

  /** Private constructor for inverse bimap. */
  private AbstractBiMap(Map<K, V> backward, AbstractBiMap<V, K> forward) {
    delegate = backward;

            

Reported by PMD.

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

Line: 53

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class AbstractBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends ForwardingMap<K, V> implements BiMap<K, V>, Serializable {

  private transient Map<K, V> delegate;
  @RetainedWith transient AbstractBiMap<V, K> inverse;

  /** Package-private constructor for creating a map-backed bimap. */

            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 55

              abstract class AbstractBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends ForwardingMap<K, V> implements BiMap<K, V>, Serializable {

  private transient Map<K, V> delegate;
  @RetainedWith transient AbstractBiMap<V, K> inverse;

  /** Package-private constructor for creating a map-backed bimap. */
  AbstractBiMap(Map<K, V> forward, Map<V, K> backward) {
    setDelegates(forward, backward);

            

Reported by PMD.

Field inverse has the same name as a method
Error

Line: 56

                  extends ForwardingMap<K, V> implements BiMap<K, V>, Serializable {

  private transient Map<K, V> delegate;
  @RetainedWith transient AbstractBiMap<V, K> inverse;

  /** Package-private constructor for creating a map-backed bimap. */
  AbstractBiMap(Map<K, V> forward, Map<V, K> backward) {
    setDelegates(forward, backward);
  }

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 97

                  checkState(inverse == null);
    checkArgument(forward.isEmpty());
    checkArgument(backward.isEmpty());
    checkArgument(forward != backward);
    delegate = forward;
    inverse = makeInverse(backward);
  }

  AbstractBiMap<V, K> makeInverse(Map<V, K> backward) {

            

Reported by PMD.

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

Line: 142

                    return value;
    }
    if (force) {
      inverse().remove(value);
    } else {
      checkArgument(!containsValue(value), "value already present: %s", value);
    }
    V oldValue = delegate.put(key, value);
    updateInverseMap(key, containedKey, oldValue, value);

            

Reported by PMD.

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

Line: 160

                    // The cast is safe because of the containedKey check.
      removeFromInverseMap(uncheckedCastNullableTToT(oldValue));
    }
    inverse.delegate.put(newValue, key);
  }

  @CanIgnoreReturnValue
  @Override
  @CheckForNull

            

Reported by PMD.

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

Line: 180

                }

  private void removeFromInverseMap(@ParametricNullness V oldValue) {
    inverse.delegate.remove(oldValue);
  }

  // Bulk Operations

  @Override

            

Reported by PMD.

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

Line: 195

                @Override
  public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
    this.delegate.replaceAll(function);
    inverse.delegate.clear();
    Entry<K, V> broken = null;
    Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
    while (itr.hasNext()) {
      Entry<K, V> entry = itr.next();
      K k = entry.getKey();

            

Reported by PMD.

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

Line: 200

                  Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
    while (itr.hasNext()) {
      Entry<K, V> entry = itr.next();
      K k = entry.getKey();
      V v = entry.getValue();
      K conflict = inverse.delegate.putIfAbsent(v, k);
      if (conflict != null) {
        broken = entry;
        // We're definitely going to throw, but we'll try to keep the BiMap in an internally

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java
37 issues
This class has too many methods, consider refactoring it.
Design

Line: 37

               */
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetReadsTester<E> extends AbstractMultisetTester<E> {

  @CollectionSize.Require(absent = ZERO)
  public void testElementSet_contains() {
    assertTrue(
        "multiset.elementSet().contains(present) returned false",

            

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

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetReadsTester<E> extends AbstractMultisetTester<E> {

  @CollectionSize.Require(absent = ZERO)
  public void testElementSet_contains() {
    assertTrue(
        "multiset.elementSet().contains(present) returned false",
        getMultiset().elementSet().contains(e0()));
  }

            

Reported by PMD.

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

Line: 43

                public void testElementSet_contains() {
    assertTrue(
        "multiset.elementSet().contains(present) returned false",
        getMultiset().elementSet().contains(e0()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testEntrySet_contains() {
    assertTrue(

            

Reported by PMD.

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

Line: 43

                public void testElementSet_contains() {
    assertTrue(
        "multiset.elementSet().contains(present) returned false",
        getMultiset().elementSet().contains(e0()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testEntrySet_contains() {
    assertTrue(

            

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

                      getMultiset().elementSet().contains(e0()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testEntrySet_contains() {
    assertTrue(
        "multiset.entrySet() didn't contain [present, 1]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e0(), 1)));
  }

            

Reported by PMD.

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

Line: 50

                public void testEntrySet_contains() {
    assertTrue(
        "multiset.entrySet() didn't contain [present, 1]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e0(), 1)));
  }

  public void testEntrySet_contains_count0() {
    assertFalse(
        "multiset.entrySet() contains [missing, 0]",

            

Reported by PMD.

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

Line: 50

                public void testEntrySet_contains() {
    assertTrue(
        "multiset.entrySet() didn't contain [present, 1]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e0(), 1)));
  }

  public void testEntrySet_contains_count0() {
    assertFalse(
        "multiset.entrySet() contains [missing, 0]",

            

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

                      getMultiset().entrySet().contains(Multisets.immutableEntry(e0(), 1)));
  }

  public void testEntrySet_contains_count0() {
    assertFalse(
        "multiset.entrySet() contains [missing, 0]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e3(), 0)));
  }


            

Reported by PMD.

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

Line: 56

                public void testEntrySet_contains_count0() {
    assertFalse(
        "multiset.entrySet() contains [missing, 0]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e3(), 0)));
  }

  public void testEntrySet_contains_nonentry() {
    assertFalse(
        "multiset.entrySet() contains a non-entry", getMultiset().entrySet().contains(e0()));

            

Reported by PMD.

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

Line: 56

                public void testEntrySet_contains_count0() {
    assertFalse(
        "multiset.entrySet() contains [missing, 0]",
        getMultiset().entrySet().contains(Multisets.immutableEntry(e3(), 0)));
  }

  public void testEntrySet_contains_nonentry() {
    assertFalse(
        "multiset.entrySet() contains a non-entry", getMultiset().entrySet().contains(e0()));

            

Reported by PMD.

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

Line: 40

               */
@GwtCompatible
public abstract class AbstractHashFloodingTest<T> extends TestCase {
  private final List<Construction<T>> constructions;
  private final IntToDoubleFunction constructionAsymptotics;
  private final List<QueryOp<T>> queries;

  AbstractHashFloodingTest(
      List<Construction<T>> constructions,

            

Reported by PMD.

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

Line: 41

              @GwtCompatible
public abstract class AbstractHashFloodingTest<T> extends TestCase {
  private final List<Construction<T>> constructions;
  private final IntToDoubleFunction constructionAsymptotics;
  private final List<QueryOp<T>> queries;

  AbstractHashFloodingTest(
      List<Construction<T>> constructions,
      IntToDoubleFunction constructionAsymptotics,

            

Reported by PMD.

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

Line: 42

              public abstract class AbstractHashFloodingTest<T> extends TestCase {
  private final List<Construction<T>> constructions;
  private final IntToDoubleFunction constructionAsymptotics;
  private final List<QueryOp<T>> queries;

  AbstractHashFloodingTest(
      List<Construction<T>> constructions,
      IntToDoubleFunction constructionAsymptotics,
      List<QueryOp<T>> queries) {

            

Reported by PMD.

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

Line: 58

                 * compareTo.
   */
  private static class CountsHashCodeAndEquals implements Comparable<CountsHashCodeAndEquals> {
    private final String delegateString;
    private final Runnable onHashCode;
    private final Runnable onEquals;
    private final Runnable onCompareTo;

    CountsHashCodeAndEquals(

            

Reported by PMD.

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

Line: 59

                 */
  private static class CountsHashCodeAndEquals implements Comparable<CountsHashCodeAndEquals> {
    private final String delegateString;
    private final Runnable onHashCode;
    private final Runnable onEquals;
    private final Runnable onCompareTo;

    CountsHashCodeAndEquals(
        String delegateString, Runnable onHashCode, Runnable onEquals, Runnable onCompareTo) {

            

Reported by PMD.

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

Line: 60

                private static class CountsHashCodeAndEquals implements Comparable<CountsHashCodeAndEquals> {
    private final String delegateString;
    private final Runnable onHashCode;
    private final Runnable onEquals;
    private final Runnable onCompareTo;

    CountsHashCodeAndEquals(
        String delegateString, Runnable onHashCode, Runnable onEquals, Runnable onCompareTo) {
      this.delegateString = delegateString;

            

Reported by PMD.

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

Line: 61

                  private final String delegateString;
    private final Runnable onHashCode;
    private final Runnable onEquals;
    private final Runnable onCompareTo;

    CountsHashCodeAndEquals(
        String delegateString, Runnable onHashCode, Runnable onEquals, Runnable onCompareTo) {
      this.delegateString = delegateString;
      this.onHashCode = onHashCode;

            

Reported by PMD.

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

Line: 93

              
  /** A holder of counters for calls to hashCode, equals, and compareTo. */
  private static final class CallsCounter {
    long hashCode;
    long equals;
    long compareTo;

    long total() {
      return hashCode + equals + compareTo;

            

Reported by PMD.

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

Line: 94

                /** A holder of counters for calls to hashCode, equals, and compareTo. */
  private static final class CallsCounter {
    long hashCode;
    long equals;
    long compareTo;

    long total() {
      return hashCode + equals + compareTo;
    }

            

Reported by PMD.

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

Line: 95

                private static final class CallsCounter {
    long hashCode;
    long equals;
    long compareTo;

    long total() {
      return hashCode + equals + compareTo;
    }


            

Reported by PMD.

guava-tests/test/com/google/common/cache/ForwardingLoadingCacheTest.java
36 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

               *
 * @author Charles Fry
 */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override

            

Reported by PMD.

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

Line: 34

               * @author Charles Fry
 */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 35

               */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 37

                private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {
    super.setUp();
    /*
     * Class parameters must be raw, so we can't create a proxy with generic

            

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

                      };
  }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {

            

Reported by PMD.

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

Line: 57

                }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);

            

Reported by PMD.

The String literal 'key' appears 14 times in this file; the first occurrence is on line 57
Error

Line: 57

                }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 58

              
  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));

            

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

                  assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));
  }

  public void testGetAll() throws ExecutionException {

            

Reported by PMD.

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

Line: 62

                }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));
  }

  public void testGetAll() throws ExecutionException {
    when(mock.getAll(ImmutableList.of("key"))).thenReturn(ImmutableMap.of("key", Boolean.TRUE));

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapEntrySetTester.java
36 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: 55

                  INSTANCE;
  }

  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 57

              
  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());

            

Reported by PMD.

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

Line: 58

                @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));

            

Reported by PMD.

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

Line: 59

                @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

            

Reported by PMD.

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

Line: 62

                  Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {

            

Reported by PMD.

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

Line: 63

                  assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));

            

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

                  assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }

            

Reported by PMD.

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

Line: 68

              
  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }


            

Reported by PMD.

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

Line: 68

              
  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 69

                public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }

  public void testContainsEntryWithIncomparableValue() {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/FilteredMultimapTest.java
36 issues
The String literal 'badkey' appears 7 times in this file; the first occurrence is on line 37
Error

Line: 37

                    new Predicate<Entry<String, Integer>>() {
        @Override
        public boolean apply(Entry<String, Integer> entry) {
          return !"badkey".equals(entry.getKey()) && !((Integer) 55556).equals(entry.getValue());
        }
      };

  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();

            

Reported by PMD.

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

Line: 43

              
  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =

            

Reported by PMD.

The String literal 'foo' appears 8 times in this file; the first occurrence is on line 43
Error

Line: 43

              
  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =

            

Reported by PMD.

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

Line: 44

                protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =
      new Predicate<String>() {

            

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

                      }
      };

  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 56

                      }
      };

  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());

            

Reported by PMD.

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

Line: 58

              
  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

            

Reported by PMD.

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

Line: 59

                public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }


            

Reported by PMD.

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

Line: 61

                  unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

  private static final Predicate<Integer> VALUE_PREDICATE =
      new Predicate<Integer>() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                  unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

  private static final Predicate<Integer> VALUE_PREDICATE =
      new Predicate<Integer>() {

            

Reported by PMD.

guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java
36 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: 33

              @GwtCompatible
public class MinimalIterableTest extends TestCase {

  public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();

            

Reported by PMD.

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

Line: 35

              
  public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }
    try {
      iterable.iterator();
      fail();

            

Reported by PMD.

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

Line: 39

                  assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }
    try {
      iterable.iterator();
      fail();

            

Reported by PMD.

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

Line: 44

                  }
    try {
      iterable.iterator();
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testOf_one() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                  }
    try {
      iterable.iterator();
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testOf_one() {

            

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

                  }
  }

  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 49

                  }
  }

  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());

            

Reported by PMD.

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

Line: 51

              
  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());
    try {
      iterator.next();

            

Reported by PMD.