The following issues were found

guava-tests/test/com/google/common/util/concurrent/MonitorTestCase.java
41 issues
This class has too many methods, consider refactoring it.
Design

Line: 30

               * @author Justin T. Sampson
 */

public abstract class MonitorTestCase extends TestCase {

  public class TestGuard extends Monitor.Guard {
    private volatile boolean satisfied;

    public TestGuard(boolean satisfied) {

            

Reported by PMD.

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

Line: 50

                  }
  }

  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;


            

Reported by PMD.

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

Line: 51

                }

  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {

            

Reported by PMD.

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

Line: 52

              
  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;

            

Reported by PMD.

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

Line: 53

                private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;
  }

            

Reported by PMD.

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

Line: 54

                private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;
  }


            

Reported by PMD.

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

Line: 60

                  this.interruptible = interruptible;
  }

  @Override
  protected final void setUp() throws Exception {
    boolean fair = new Random().nextBoolean();
    monitor = new Monitor(fair);
    tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
    tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 68

                  tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
  }

  @Override
  protected final void tearDown() {
    tearDownStack.runTearDown();
  }

  private String enter() {

            

Reported by PMD.

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

Line: 101

                  return "leave";
  }

  public final void testMutualExclusion() throws Exception {
    thread1.callAndAssertReturns(enter());
    thread2.callAndAssertBlocks(enter());
    thread1.callAndAssertReturns(leave());
    thread2.assertPriorCallReturns(enter());
  }

            

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

                  return "leave";
  }

  public final void testMutualExclusion() throws Exception {
    thread1.callAndAssertReturns(enter());
    thread2.callAndAssertBlocks(enter());
    thread1.callAndAssertReturns(leave());
    thread2.assertPriorCallReturns(enter());
  }

            

Reported by PMD.

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

Line: 58

                    checkArgument((extraCharacteristics & Spliterator.SORTED) != 0);
    }
    class WithCharacteristics implements Spliterator<T> {
      private final Spliterator.OfInt delegate;

      WithCharacteristics(Spliterator.OfInt delegate) {
        this.delegate = delegate;
      }


            

Reported by PMD.

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

Line: 104

                      }
      }
    }
    return new WithCharacteristics(IntStream.range(0, size).spliterator());
  }

  /**
   * Returns a {@code Spliterator} over the elements of {@code fromSpliterator} mapped by {@code
   * function}.

            

Reported by PMD.

Avoid using redundant field initializer for 'holder'
Performance

Line: 156

                  checkNotNull(fromSpliterator);
    checkNotNull(predicate);
    class Splitr implements Spliterator<T>, Consumer<T> {
      @CheckForNull T holder = null;

      @Override
      public void accept(@ParametricNullness T t) {
        this.holder = t;
      }

            

Reported by PMD.

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

Line: 156

                  checkNotNull(fromSpliterator);
    checkNotNull(predicate);
    class Splitr implements Spliterator<T>, Consumer<T> {
      @CheckForNull T holder = null;

      @Override
      public void accept(@ParametricNullness T t) {
        this.holder = t;
      }

            

Reported by PMD.

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

Line: 174

                            return true;
            }
          } finally {
            holder = null;
          }
        }
        return false;
      }


            

Reported by PMD.

The String literal 'flatMap does not support SUBSIZED characteristic' appears 4 times in this file; the first occurrence is on line 222
Error

Line: 222

                        long topSize) {
    checkArgument(
        (topCharacteristics & Spliterator.SUBSIZED) == 0,
        "flatMap does not support SUBSIZED characteristic");
    checkArgument(
        (topCharacteristics & Spliterator.SORTED) == 0,
        "flatMap does not support SORTED characteristic");
    checkNotNull(fromSpliterator);
    checkNotNull(function);

            

Reported by PMD.

The String literal 'flatMap does not support SORTED characteristic' appears 4 times in this file; the first occurrence is on line 225
Error

Line: 225

                      "flatMap does not support SUBSIZED characteristic");
    checkArgument(
        (topCharacteristics & Spliterator.SORTED) == 0,
        "flatMap does not support SORTED characteristic");
    checkNotNull(fromSpliterator);
    checkNotNull(function);
    return new FlatMapSpliteratorOfObject<InElementT, OutElementT>(
        null, fromSpliterator, function, topCharacteristics, topSize);
  }

            

Reported by PMD.

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

Line: 321

                        long estSplitSize);
    }

    @Weak @CheckForNull OutSpliteratorT prefix;
    final Spliterator<InElementT> from;
    final Function<? super InElementT, OutSpliteratorT> function;
    final Factory<InElementT, OutSpliteratorT> factory;
    int characteristics;
    long estimatedSize;

            

Reported by PMD.

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

Line: 322

                  }

    @Weak @CheckForNull OutSpliteratorT prefix;
    final Spliterator<InElementT> from;
    final Function<? super InElementT, OutSpliteratorT> function;
    final Factory<InElementT, OutSpliteratorT> factory;
    int characteristics;
    long estimatedSize;


            

Reported by PMD.

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

Line: 323

              
    @Weak @CheckForNull OutSpliteratorT prefix;
    final Spliterator<InElementT> from;
    final Function<? super InElementT, OutSpliteratorT> function;
    final Factory<InElementT, OutSpliteratorT> factory;
    int characteristics;
    long estimatedSize;

    FlatMapSpliterator(

            

Reported by PMD.

guava/src/com/google/common/collect/ImmutableRangeMap.java
41 issues
The class 'ImmutableRangeMap' has a Modified Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 50

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

The class 'ImmutableRangeMap' has a Standard Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 50

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

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

Line: 50

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

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

Line: 90

                    return (ImmutableRangeMap<K, V>) rangeMap;
    }
    Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
    ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
    for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
      rangesBuilder.add(entry.getKey());
      valuesBuilder.add(entry.getValue());
    }

            

Reported by PMD.

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

Line: 91

                  }
    Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
    ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
    for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
      rangesBuilder.add(entry.getKey());
      valuesBuilder.add(entry.getValue());
    }
    return new ImmutableRangeMap<>(rangesBuilder.build(), valuesBuilder.build());

            

Reported by PMD.

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

Line: 111

                 */
  @DoNotMock
  public static final class Builder<K extends Comparable<?>, V> {
    private final List<Entry<Range<K>, V>> entries;

    public Builder() {
      this.entries = Lists.newArrayList();
    }


            

Reported by PMD.

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

Line: 134

                  /** Copies all associations from the specified range map into this builder. */
    @CanIgnoreReturnValue
    public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) {
      for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
        put(entry.getKey(), entry.getValue());
      }
      return this;
    }


            

Reported by PMD.

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

Line: 153

                   * @throws IllegalArgumentException if any two ranges inserted into this builder overlap
     */
    public ImmutableRangeMap<K, V> build() {
      Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
      ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {

            

Reported by PMD.

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

Line: 153

                   * @throws IllegalArgumentException if any two ranges inserted into this builder overlap
     */
    public ImmutableRangeMap<K, V> build() {
      Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
      ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {

            

Reported by PMD.

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

Line: 157

                    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {
          Range<K> prevRange = entries.get(i - 1).getKey();
          if (range.isConnected(prevRange) && !range.intersection(prevRange).isEmpty()) {
            throw new IllegalArgumentException(
                "Overlapping ranges: range " + prevRange + " overlaps with entry " + range);

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/ExecutionSequencer.java
41 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 95

                }

  /** This reference acts as a pointer tracking the head of a linked list of ListenableFutures. */
  private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**

            

Reported by PMD.

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

Line: 98

                private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**
   * This object is unsafely published, but avoids problematic races by relying exclusively on the
   * identity equality of its Thread field so that the task field is only accessed by a single
   * thread.

            

Reported by PMD.

Avoid unused private fields such as 'latestTaskQueue'.
Design

Line: 98

                private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**
   * This object is unsafely published, but avoids problematic races by relying exclusively on the
   * identity equality of its Thread field so that the task field is only accessed by a single
   * thread.

            

Reported by PMD.

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

Line: 129

                   * All the states where thread != currentThread are identical for our purposes, and so even
     * though it's racy, we don't care which of those values we get, so no need to synchronize.
     */
    @CheckForNull Thread thread;
    /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

            

Reported by PMD.

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

Line: 131

                   */
    @CheckForNull Thread thread;
    /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

  /**

            

Reported by PMD.

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

Line: 133

                  /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

  /**
   * Enqueues a task to run when the previous task (if any) completes.
   *

            

Reported by PMD.

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

Line: 206

              
    // Invoke our task once the previous future completes.
    final TrustedListenableFutureTask<T> taskFuture = TrustedListenableFutureTask.create(task);
    oldFuture.addListener(taskFuture, taskExecutor);

    final ListenableFuture<T> outputFuture = Futures.nonCancellationPropagating(taskFuture);

    // newFuture's lifetime is determined by taskFuture, which can't complete before oldFuture
    // unless taskFuture is cancelled, in which case it falls back to oldFuture. This ensures that

            

Reported by PMD.

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

Line: 257

                  // Adding the listener to both futures guarantees that newFuture will aways be set. Adding to
    // taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
    // propagates cancellation if the callable has not yet been invoked.
    outputFuture.addListener(listener, directExecutor());
    taskFuture.addListener(listener, directExecutor());

    return outputFuture;
  }


            

Reported by PMD.

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

Line: 258

                  // taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
    // propagates cancellation if the callable has not yet been invoked.
    outputFuture.addListener(listener, directExecutor());
    taskFuture.addListener(listener, directExecutor());

    return outputFuture;
  }

  enum RunningState {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 287

                 * properties; for example, calling WeakReference.get() on Android will block during an
   * otherwise-concurrent GC cycle.
   */
  private static final class TaskNonReentrantExecutor extends AtomicReference<RunningState>
      implements Executor, Runnable {

    /**
     * Used to update and read the latestTaskQueue field. Set to null once the runnable has been run
     * or queued.

            

Reported by PMD.

android/guava/src/com/google/common/cache/CacheBuilder.java
41 issues
The class 'CacheBuilder' has a Modified Cyclomatic Complexity of 1 (Highest = 12).
Design

Line: 195

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
  private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

            

Reported by PMD.

Possible God Class (WMC=68, ATFD=10, TCC=12.327%)
Design

Line: 195

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
  private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

            

Reported by PMD.

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

Line: 195

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
  private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

            

Reported by PMD.

Too many fields
Design

Line: 195

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
  private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

            

Reported by PMD.

The class 'CacheBuilder' has a Standard Cyclomatic Complexity of 1 (Highest = 12).
Design

Line: 195

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class CacheBuilder<K, V> {
  private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

            

Reported by PMD.

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

Line: 199

                private static final int DEFAULT_INITIAL_CAPACITY = 16;
  private static final int DEFAULT_CONCURRENCY_LEVEL = 4;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_EXPIRATION_NANOS = 0;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private static final int DEFAULT_REFRESH_NANOS = 0;


            

Reported by PMD.

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

Line: 268

              
  static final int UNSET_INT = -1;

  boolean strictParsing = true;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;
  long maximumSize = UNSET_INT;
  long maximumWeight = UNSET_INT;

            

Reported by PMD.

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

Line: 270

              
  boolean strictParsing = true;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;
  long maximumSize = UNSET_INT;
  long maximumWeight = UNSET_INT;
  @Nullable Weigher<? super K, ? super V> weigher;


            

Reported by PMD.

Field initialCapacity has the same name as a method
Error

Line: 270

              
  boolean strictParsing = true;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;
  long maximumSize = UNSET_INT;
  long maximumWeight = UNSET_INT;
  @Nullable Weigher<? super K, ? super V> weigher;


            

Reported by PMD.

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

Line: 271

                boolean strictParsing = true;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;
  long maximumSize = UNSET_INT;
  long maximumWeight = UNSET_INT;
  @Nullable Weigher<? super K, ? super V> weigher;

  @Nullable Strength keyStrength;

            

Reported by PMD.

android/guava/src/com/google/common/collect/ImmutableRangeMap.java
41 issues
The class 'ImmutableRangeMap' has a Standard Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 46

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

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

Line: 46

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

The class 'ImmutableRangeMap' has a Modified Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 46

              @Beta
@GwtIncompatible // NavigableMap
@ElementTypesAreNonnullByDefault
public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {

  private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY =
      new ImmutableRangeMap<>(ImmutableList.<Range<Comparable<?>>>of(), ImmutableList.of());

  /**

            

Reported by PMD.

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

Line: 73

                    return (ImmutableRangeMap<K, V>) rangeMap;
    }
    Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
    ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
    for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
      rangesBuilder.add(entry.getKey());
      valuesBuilder.add(entry.getValue());
    }

            

Reported by PMD.

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

Line: 74

                  }
    Map<Range<K>, ? extends V> map = rangeMap.asMapOfRanges();
    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(map.size());
    ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(map.size());
    for (Entry<Range<K>, ? extends V> entry : map.entrySet()) {
      rangesBuilder.add(entry.getKey());
      valuesBuilder.add(entry.getValue());
    }
    return new ImmutableRangeMap<>(rangesBuilder.build(), valuesBuilder.build());

            

Reported by PMD.

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

Line: 94

                 */
  @DoNotMock
  public static final class Builder<K extends Comparable<?>, V> {
    private final List<Entry<Range<K>, V>> entries;

    public Builder() {
      this.entries = Lists.newArrayList();
    }


            

Reported by PMD.

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

Line: 117

                  /** Copies all associations from the specified range map into this builder. */
    @CanIgnoreReturnValue
    public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) {
      for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
        put(entry.getKey(), entry.getValue());
      }
      return this;
    }


            

Reported by PMD.

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

Line: 136

                   * @throws IllegalArgumentException if any two ranges inserted into this builder overlap
     */
    public ImmutableRangeMap<K, V> build() {
      Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
      ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {

            

Reported by PMD.

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

Line: 136

                   * @throws IllegalArgumentException if any two ranges inserted into this builder overlap
     */
    public ImmutableRangeMap<K, V> build() {
      Collections.sort(entries, Range.<K>rangeLexOrdering().onKeys());
      ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {

            

Reported by PMD.

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

Line: 140

                    ImmutableList.Builder<Range<K>> rangesBuilder = new ImmutableList.Builder<>(entries.size());
      ImmutableList.Builder<V> valuesBuilder = new ImmutableList.Builder<V>(entries.size());
      for (int i = 0; i < entries.size(); i++) {
        Range<K> range = entries.get(i).getKey();
        if (i > 0) {
          Range<K> prevRange = entries.get(i - 1).getKey();
          if (range.isConnected(prevRange) && !range.intersection(prevRange).isEmpty()) {
            throw new IllegalArgumentException(
                "Overlapping ranges: range " + prevRange + " overlaps with entry " + range);

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/MonitorTestCase.java
41 issues
This class has too many methods, consider refactoring it.
Design

Line: 30

               * @author Justin T. Sampson
 */

public abstract class MonitorTestCase extends TestCase {

  public class TestGuard extends Monitor.Guard {
    private volatile boolean satisfied;

    public TestGuard(boolean satisfied) {

            

Reported by PMD.

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

Line: 50

                  }
  }

  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;


            

Reported by PMD.

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

Line: 51

                }

  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {

            

Reported by PMD.

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

Line: 52

              
  private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;

            

Reported by PMD.

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

Line: 53

                private final boolean interruptible;
  private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;
  }

            

Reported by PMD.

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

Line: 54

                private Monitor monitor;
  private final TearDownStack tearDownStack = new TearDownStack(true);
  private TestThread<Monitor> thread1;
  private TestThread<Monitor> thread2;

  protected MonitorTestCase(boolean interruptible) {
    this.interruptible = interruptible;
  }


            

Reported by PMD.

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

Line: 60

                  this.interruptible = interruptible;
  }

  @Override
  protected final void setUp() throws Exception {
    boolean fair = new Random().nextBoolean();
    monitor = new Monitor(fair);
    tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
    tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 68

                  tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
  }

  @Override
  protected final void tearDown() {
    tearDownStack.runTearDown();
  }

  private String enter() {

            

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

                  return "leave";
  }

  public final void testMutualExclusion() throws Exception {
    thread1.callAndAssertReturns(enter());
    thread2.callAndAssertBlocks(enter());
    thread1.callAndAssertReturns(leave());
    thread2.assertPriorCallReturns(enter());
  }

            

Reported by PMD.

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

Line: 101

                  return "leave";
  }

  public final void testMutualExclusion() throws Exception {
    thread1.callAndAssertReturns(enter());
    thread2.callAndAssertBlocks(enter());
    thread1.callAndAssertReturns(leave());
    thread2.assertPriorCallReturns(enter());
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/AtomicLongMapBasherTest.java
41 issues
The class 'AtomicLongMapBasherTest' has a Standard Cyclomatic Complexity of 17 (Highest = 16).
Design

Line: 35

               */
@GwtIncompatible // threads

public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;

            

Reported by PMD.

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

Line: 36

              @GwtIncompatible // threads

public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;

            

Reported by PMD.

The method 'testModify_basher()' has a NCSS line count of 65.
Design

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

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

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

The method 'testModify_basher' has a Standard Cyclomatic Complexity of 16.
Design

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "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: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

                    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError =
          threadPool.submit(
              new Runnable() {
                @Override
                public void run() {
                  int threadSum = 0;
                  for (int j = 0; j < getsPerTask; j++) {
                    long delta = random.nextInt(deltaRange);

            

Reported by PMD.

The method 'run' has a Standard Cyclomatic Complexity of 14.
Design

Line: 55

                        threadPool.submit(
              new Runnable() {
                @Override
                public void run() {
                  int threadSum = 0;
                  for (int j = 0; j < getsPerTask; j++) {
                    long delta = random.nextInt(deltaRange);
                    int behavior = random.nextInt(10);
                    switch (behavior) {

            

Reported by PMD.

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

Line: 114

                            });
    }

    threadPool.shutdown();
    assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

    assertEquals(sum.get(), map.get(key));
  }
}

            

Reported by PMD.

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

Line: 115

                  }

    threadPool.shutdown();
    assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

    assertEquals(sum.get(), map.get(key));
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java
41 issues
A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 44

                }

  @Override
  protected abstract SortedMap<K, V> makeEmptyMap() throws UnsupportedOperationException;

  @Override
  protected abstract SortedMap<K, V> makePopulatedMap() throws UnsupportedOperationException;

  @Override

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 47

                protected abstract SortedMap<K, V> makeEmptyMap() throws UnsupportedOperationException;

  @Override
  protected abstract SortedMap<K, V> makePopulatedMap() throws UnsupportedOperationException;

  @Override
  protected SortedMap<K, V> makeEitherMap() {
    try {
      return makePopulatedMap();

            

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

                  }
  }

  public void testTailMapWriteThrough() {
    final SortedMap<K, V> map;
    try {
      map = makePopulatedMap();
    } catch (UnsupportedOperationException e) {
      return;

            

Reported by PMD.

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

Line: 58

                  }
  }

  public void testTailMapWriteThrough() {
    final SortedMap<K, V> map;
    try {
      map = makePopulatedMap();
    } catch (UnsupportedOperationException e) {
      return;

            

Reported by PMD.

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

Line: 65

                  } catch (UnsupportedOperationException e) {
      return;
    }
    if (map.size() < 2 || !supportsPut) {
      return;
    }
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    Entry<K, V> firstEntry = iterator.next();
    Entry<K, V> secondEntry = iterator.next();

            

Reported by PMD.

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

Line: 68

                  if (map.size() < 2 || !supportsPut) {
      return;
    }
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    Entry<K, V> firstEntry = iterator.next();
    Entry<K, V> secondEntry = iterator.next();
    K key = secondEntry.getKey();
    SortedMap<K, V> subMap = map.tailMap(key);
    V value = getValueNotInPopulatedMap();

            

Reported by PMD.

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

Line: 68

                  if (map.size() < 2 || !supportsPut) {
      return;
    }
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    Entry<K, V> firstEntry = iterator.next();
    Entry<K, V> secondEntry = iterator.next();
    K key = secondEntry.getKey();
    SortedMap<K, V> subMap = map.tailMap(key);
    V value = getValueNotInPopulatedMap();

            

Reported by PMD.

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

Line: 71

                  Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    Entry<K, V> firstEntry = iterator.next();
    Entry<K, V> secondEntry = iterator.next();
    K key = secondEntry.getKey();
    SortedMap<K, V> subMap = map.tailMap(key);
    V value = getValueNotInPopulatedMap();
    subMap.put(key, value);
    assertEquals(secondEntry.getValue(), value);
    assertEquals(map.get(key), value);

            

Reported by PMD.

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

Line: 72

                  Entry<K, V> firstEntry = iterator.next();
    Entry<K, V> secondEntry = iterator.next();
    K key = secondEntry.getKey();
    SortedMap<K, V> subMap = map.tailMap(key);
    V value = getValueNotInPopulatedMap();
    subMap.put(key, value);
    assertEquals(secondEntry.getValue(), value);
    assertEquals(map.get(key), value);
    try {

            

Reported by PMD.

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

Line: 74

                  K key = secondEntry.getKey();
    SortedMap<K, V> subMap = map.tailMap(key);
    V value = getValueNotInPopulatedMap();
    subMap.put(key, value);
    assertEquals(secondEntry.getValue(), value);
    assertEquals(map.get(key), value);
    try {
      subMap.put(firstEntry.getKey(), value);
      fail("Expected IllegalArgumentException");

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java
41 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 95

                }

  /** This reference acts as a pointer tracking the head of a linked list of ListenableFutures. */
  private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**

            

Reported by PMD.

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

Line: 98

                private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**
   * This object is unsafely published, but avoids problematic races by relying exclusively on the
   * identity equality of its Thread field so that the task field is only accessed by a single
   * thread.

            

Reported by PMD.

Avoid unused private fields such as 'latestTaskQueue'.
Design

Line: 98

                private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
      new AtomicReference<>(immediateVoidFuture());

  private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();

  /**
   * This object is unsafely published, but avoids problematic races by relying exclusively on the
   * identity equality of its Thread field so that the task field is only accessed by a single
   * thread.

            

Reported by PMD.

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

Line: 129

                   * All the states where thread != currentThread are identical for our purposes, and so even
     * though it's racy, we don't care which of those values we get, so no need to synchronize.
     */
    @CheckForNull Thread thread;
    /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

            

Reported by PMD.

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

Line: 131

                   */
    @CheckForNull Thread thread;
    /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

  /**

            

Reported by PMD.

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

Line: 133

                  /** Only used by the thread associated with this object */
    @CheckForNull Runnable nextTask;
    /** Only used by the thread associated with this object */
    @CheckForNull Executor nextExecutor;
  }

  /**
   * Enqueues a task to run when the previous task (if any) completes.
   *

            

Reported by PMD.

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

Line: 206

              
    // Invoke our task once the previous future completes.
    final TrustedListenableFutureTask<T> taskFuture = TrustedListenableFutureTask.create(task);
    oldFuture.addListener(taskFuture, taskExecutor);

    final ListenableFuture<T> outputFuture = Futures.nonCancellationPropagating(taskFuture);

    // newFuture's lifetime is determined by taskFuture, which can't complete before oldFuture
    // unless taskFuture is cancelled, in which case it falls back to oldFuture. This ensures that

            

Reported by PMD.

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

Line: 257

                  // Adding the listener to both futures guarantees that newFuture will aways be set. Adding to
    // taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
    // propagates cancellation if the callable has not yet been invoked.
    outputFuture.addListener(listener, directExecutor());
    taskFuture.addListener(listener, directExecutor());

    return outputFuture;
  }


            

Reported by PMD.

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

Line: 258

                  // taskFuture guarantees completion if the callable is invoked, and adding to outputFuture
    // propagates cancellation if the callable has not yet been invoked.
    outputFuture.addListener(listener, directExecutor());
    taskFuture.addListener(listener, directExecutor());

    return outputFuture;
  }

  enum RunningState {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 287

                 * properties; for example, calling WeakReference.get() on Android will block during an
   * otherwise-concurrent GC cycle.
   */
  private static final class TaskNonReentrantExecutor extends AtomicReference<RunningState>
      implements Executor, Runnable {

    /**
     * Used to update and read the latestTaskQueue field. Set to null once the runnable has been run
     * or queued.

            

Reported by PMD.