The following issues were found

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

Line: 46

               */
@GwtCompatible(serializable = true, emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class ImmutableBiMap<K, V> extends ImmutableBiMapFauxverideShim<K, V>
    implements BiMap<K, V> {

  /**
   * Returns a {@link Collector} that accumulates elements into an {@code ImmutableBiMap} whose keys
   * and values are the result of applying the provided mapping functions to the input elements.

            

Reported by PMD.

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

Line: 47

              @GwtCompatible(serializable = true, emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class ImmutableBiMap<K, V> extends ImmutableBiMapFauxverideShim<K, V>
    implements BiMap<K, V> {

  /**
   * Returns a {@link Collector} that accumulates elements into an {@code ImmutableBiMap} whose keys
   * and values are the result of applying the provided mapping functions to the input elements.
   * Entries appear in the result {@code ImmutableBiMap} in encounter order.

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 117

                 *
   * @throws IllegalArgumentException if duplicate keys or values are added
   */
  public static <K, V> ImmutableBiMap<K, V> of(
      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    return RegularImmutableBiMap.fromEntries(
        entryOf(k1, v1), entryOf(k2, v2), entryOf(k3, v3), entryOf(k4, v4), entryOf(k5, v5));
  }


            

Reported by PMD.

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

Line: 283

                      case 1:
          // requireNonNull is safe because the first `size` elements have been filled in.
          Entry<K, V> onlyEntry = requireNonNull(entries[0]);
          return of(onlyEntry.getKey(), onlyEntry.getValue());
        default:
          /*
           * If entries is full, or if hash flooding is detected, then this implementation may end
           * up using the entries array directly and writing over the entry objects with
           * non-terminal entries, but this is safe; if this Builder is used further, it will grow

            

Reported by PMD.

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

Line: 283

                      case 1:
          // requireNonNull is safe because the first `size` elements have been filled in.
          Entry<K, V> onlyEntry = requireNonNull(entries[0]);
          return of(onlyEntry.getKey(), onlyEntry.getValue());
        default:
          /*
           * If entries is full, or if hash flooding is detected, then this implementation may end
           * up using the entries array directly and writing over the entry objects with
           * non-terminal entries, but this is safe; if this Builder is used further, it will grow

            

Reported by PMD.

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

Line: 300

                              entries,
                0,
                size,
                Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
          }
          entriesUsed = true;
          return RegularImmutableBiMap.fromEntryArray(size, entries);
      }
    }

            

Reported by PMD.

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

Line: 319

                      case 1:
          // requireNonNull is safe because the first `size` elements have been filled in.
          Entry<K, V> onlyEntry = requireNonNull(entries[0]);
          return of(onlyEntry.getKey(), onlyEntry.getValue());
        default:
          entriesUsed = true;
          return RegularImmutableBiMap.fromEntryArray(size, entries);
      }
    }

            

Reported by PMD.

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

Line: 319

                      case 1:
          // requireNonNull is safe because the first `size` elements have been filled in.
          Entry<K, V> onlyEntry = requireNonNull(entries[0]);
          return of(onlyEntry.getKey(), onlyEntry.getValue());
        default:
          entriesUsed = true;
          return RegularImmutableBiMap.fromEntryArray(size, entries);
      }
    }

            

Reported by PMD.

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

Line: 349

                    ImmutableBiMap<K, V> bimap = (ImmutableBiMap<K, V>) map;
      // TODO(lowasser): if we need to make a copy of a BiMap because the
      // forward map is a view, don't make a copy of the non-view delegate map
      if (!bimap.isPartialView()) {
        return bimap;
      }
    }
    return copyOf(map.entrySet());
  }

            

Reported by PMD.

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

Line: 375

                      return of();
      case 1:
        Entry<K, V> entry = entryArray[0];
        return of(entry.getKey(), entry.getValue());
      default:
        /*
         * The current implementation will end up using entryArray directly, though it will write
         * over the (arbitrary, potentially mutable) Entry objects actually stored in entryArray.
         */

            

Reported by PMD.

guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java
12 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 59

                @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();
    ByteBuffer buffer = ByteBuffer.allocate(len * 2).order(ByteOrder.LITTLE_ENDIAN);
    for (int i = 0; i < len; i++) {
      buffer.putChar(input.charAt(i));
    }
    return hashBytes(buffer.array());
  }

            

Reported by PMD.

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

Line: 63

                  for (int i = 0; i < len; i++) {
      buffer.putChar(input.charAt(i));
    }
    return hashBytes(buffer.array());
  }

  @Override
  public HashCode hashString(CharSequence input, Charset charset) {
    return hashBytes(input.toString().getBytes(charset));

            

Reported by PMD.

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

Line: 68

              
  @Override
  public HashCode hashString(CharSequence input, Charset charset) {
    return hashBytes(input.toString().getBytes(charset));
  }

  @Override
  public abstract HashCode hashBytes(byte[] input, int off, int len);


            

Reported by PMD.

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

Line: 76

              
  @Override
  public HashCode hashBytes(ByteBuffer input) {
    return newHasher(input.remaining()).putBytes(input).hash();
  }

  /** In-memory stream-based implementation of Hasher. */
  private final class BufferingHasher extends AbstractHasher {
    final ExposedByteArrayOutputStream stream;

            

Reported by PMD.

guava/src/com/google/common/base/Suppliers.java
12 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 56

              
  private static class SupplierComposition<F extends @Nullable Object, T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Function<? super F, T> function;
    final Supplier<F> supplier;

    SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
      this.function = checkNotNull(function);
      this.supplier = checkNotNull(supplier);

            

Reported by PMD.

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

Line: 57

                private static class SupplierComposition<F extends @Nullable Object, T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Function<? super F, T> function;
    final Supplier<F> supplier;

    SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
      this.function = checkNotNull(function);
      this.supplier = checkNotNull(supplier);
    }

            

Reported by PMD.

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

Line: 120

              
  @VisibleForTesting
  static class MemoizingSupplier<T extends @Nullable Object> implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    transient volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull transient T value;


            

Reported by PMD.

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

Line: 160

              
  @VisibleForTesting
  static class NonSerializableMemoizingSupplier<T extends @Nullable Object> implements Supplier<T> {
    @CheckForNull volatile Supplier<T> delegate;
    volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;


            

Reported by PMD.

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

Line: 161

                @VisibleForTesting
  static class NonSerializableMemoizingSupplier<T extends @Nullable Object> implements Supplier<T> {
    @CheckForNull volatile Supplier<T> delegate;
    volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;

    NonSerializableMemoizingSupplier(Supplier<T> delegate) {

            

Reported by PMD.

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

Line: 164

                  volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;

    NonSerializableMemoizingSupplier(Supplier<T> delegate) {
      this.delegate = checkNotNull(delegate);
    }


            

Reported by PMD.

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

Line: 183

                           * TODO(cpovirk): To avoid having to check for null, replace `delegate` with a singleton
             * `Supplier` that always throws an exception.
             */
            T t = requireNonNull(delegate).get();
            value = t;
            initialized = true;
            // Release the delegate to GC.
            delegate = null;
            return t;

            

Reported by PMD.

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

Line: 187

                          value = t;
            initialized = true;
            // Release the delegate to GC.
            delegate = null;
            return t;
          }
        }
      }
      // This is safe because we checked `initialized.`

            

Reported by PMD.

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

Line: 236

                @SuppressWarnings("GoodTime") // lots of violations
  static class ExpiringMemoizingSupplier<T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    final long durationNanos;
    @CheckForNull transient volatile T value;
    // The special value 0 means "not yet initialized".
    transient volatile long expirationNanos;


            

Reported by PMD.

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

Line: 237

                static class ExpiringMemoizingSupplier<T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    final long durationNanos;
    @CheckForNull transient volatile T value;
    // The special value 0 means "not yet initialized".
    transient volatile long expirationNanos;

    ExpiringMemoizingSupplier(Supplier<T> delegate, long duration, TimeUnit unit) {

            

Reported by PMD.

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

Line: 36

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }

            

Reported by PMD.

Field endpoint has the same name as a method
Error

Line: 37

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }


            

Reported by PMD.

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

Line: 37

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }


            

Reported by PMD.

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

Line: 123

              
  private static final long serialVersionUID = 0;

  private static final class BelowAll extends Cut<Comparable<?>> {
    private static final BelowAll INSTANCE = new BelowAll();

    private BelowAll() {
      /*
       * No code ever sees this bogus value for `endpoint`: This class overrides both methods that

            

Reported by PMD.

The String literal 'this statement should be unreachable' appears 4 times in this file; the first occurrence is on line 153
Error

Line: 153

              
    @Override
    BoundType typeAsUpperBound() {
      throw new AssertionError("this statement should be unreachable");
    }

    @Override
    Cut<Comparable<?>> withLowerBoundType(
        BoundType boundType, DiscreteDomain<Comparable<?>> domain) {

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 199

              
    @Override
    public int compareTo(Cut<Comparable<?>> o) {
      return (o == this) ? 0 : -1;
    }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);

            

Reported by PMD.

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

Line: 228

                  return (Cut<C>) AboveAll.INSTANCE;
  }

  private static final class AboveAll extends Cut<Comparable<?>> {
    private static final AboveAll INSTANCE = new AboveAll();

    private AboveAll() {
      // For discussion of "", see BelowAll.
      super("");

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 290

              
    @Override
    public int compareTo(Cut<Comparable<?>> o) {
      return (o == this) ? 0 : 1;
    }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);

            

Reported by PMD.

Ensure you override both equals() and hashCode()
Error

Line: 294

                  }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);
    }

    @Override
    public String toString() {

            

Reported by PMD.

Ensure you override both equals() and hashCode()
Error

Line: 382

                  }

    @Override
    public int hashCode() {
      return endpoint.hashCode();
    }

    @Override
    public String toString() {

            

Reported by PMD.

guava/src/com/google/common/io/ByteSink.java
12 issues
Ensure that resources like this OutputStream object are closed after use
Error

Line: 102

              
    Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 103

                  Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 104

                  try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

            

Reported by PMD.

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

Line: 105

                    OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

Ensure that resources like this OutputStream object are closed after use
Error

Line: 125

              
    Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);

            

Reported by PMD.

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

Line: 127

                  try {
      OutputStream out = closer.register(openStream());
      long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 129

                    long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 142

                 */
  private final class AsCharSink extends CharSink {

    private final Charset charset;

    private AsCharSink(Charset charset) {
      this.charset = checkNotNull(charset);
    }


            

Reported by PMD.

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

Line: 150

              
    @Override
    public Writer openStream() throws IOException {
      return new OutputStreamWriter(ByteSink.this.openStream(), charset);
    }

    @Override
    public String toString() {
      return ByteSink.this.toString() + ".asCharSink(" + charset + ")";

            

Reported by PMD.

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

Line: 150

              
    @Override
    public Writer openStream() throws IOException {
      return new OutputStreamWriter(ByteSink.this.openStream(), charset);
    }

    @Override
    public String toString() {
      return ByteSink.this.toString() + ".asCharSink(" + charset + ")";

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/InterruptionUtil.java
11 issues
All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 35

               * @author Kevin Bourrillion
 * @author Chris Povirk
 */
final class InterruptionUtil {
  private static final Logger logger = Logger.getLogger(InterruptionUtil.class.getName());

  /** Runnable which will interrupt the target thread repeatedly when run. */
  private static final class Interruptenator implements Runnable {
    private final long everyMillis;

            

Reported by PMD.

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

Line: 40

              
  /** Runnable which will interrupt the target thread repeatedly when run. */
  private static final class Interruptenator implements Runnable {
    private final long everyMillis;
    private final Thread interruptee;
    private volatile boolean shouldStop = false;

    Interruptenator(Thread interruptee, long everyMillis) {
      this.everyMillis = everyMillis;

            

Reported by PMD.

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

Line: 41

                /** Runnable which will interrupt the target thread repeatedly when run. */
  private static final class Interruptenator implements Runnable {
    private final long everyMillis;
    private final Thread interruptee;
    private volatile boolean shouldStop = false;

    Interruptenator(Thread interruptee, long everyMillis) {
      this.everyMillis = everyMillis;
      this.interruptee = interruptee;

            

Reported by PMD.

Avoid using redundant field initializer for 'shouldStop'
Performance

Line: 42

                private static final class Interruptenator implements Runnable {
    private final long everyMillis;
    private final Thread interruptee;
    private volatile boolean shouldStop = false;

    Interruptenator(Thread interruptee, long everyMillis) {
      this.everyMillis = everyMillis;
      this.interruptee = interruptee;
    }

            

Reported by PMD.

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

Line: 42

                private static final class Interruptenator implements Runnable {
    private final long everyMillis;
    private final Thread interruptee;
    private volatile boolean shouldStop = false;

    Interruptenator(Thread interruptee, long everyMillis) {
      this.everyMillis = everyMillis;
      this.interruptee = interruptee;
    }

            

Reported by PMD.

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

Line: 96

                  interruptingThread.start();
    tearDownAccepter.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() throws Exception {
            interruptingTask.stopInterrupting();
            interruptingThread.interrupt();
            joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
            Thread.interrupted();

            

Reported by PMD.

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

Line: 134

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

            

Reported by PMD.

Found 'DU'-anomaly for variable 'interruptee' (lines '72'-'86').
Error

Line: 72

                /** Interrupts the current thread after sleeping for the specified delay. */
  static void requestInterruptIn(final long time, final TimeUnit unit) {
    checkNotNull(unit);
    final Thread interruptee = Thread.currentThread();
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'interruptee' (lines '72'-'86').
Error

Line: 72

                /** Interrupts the current thread after sleeping for the specified delay. */
  static void requestInterruptIn(final long time, final TimeUnit unit) {
    checkNotNull(unit);
    final Thread interruptee = Thread.currentThread();
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'interrupted' (lines '117'-'137').
Error

Line: 117

              
  // TODO(cpovirk): promote to Uninterruptibles, and add untimed version
  private static void joinUninterruptibly(Thread thread, long timeout, TimeUnit unit) {
    boolean interrupted = false;
    try {
      long remainingNanos = unit.toNanos(timeout);
      long end = System.nanoTime() + remainingNanos;

      while (true) {

            

Reported by PMD.

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

Line: 50

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class EnumMultiset<E extends Enum<E>> extends AbstractMultiset<E>
    implements Serializable {
  /** Creates an empty {@code EnumMultiset}. */
  public static <E extends Enum<E>> EnumMultiset<E> create(Class<E> type) {
    return new EnumMultiset<E>(type);
  }


            

Reported by PMD.

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

Line: 67

                public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements) {
    Iterator<E> iterator = elements.iterator();
    checkArgument(iterator.hasNext(), "EnumMultiset constructor passed empty Iterable");
    EnumMultiset<E> multiset = new EnumMultiset<>(iterator.next().getDeclaringClass());
    Iterables.addAll(multiset, elements);
    return multiset;
  }

  /**

            

Reported by PMD.

Field distinctElements has the same name as a method
Error

Line: 87

                private transient Class<E> type;
  private transient E[] enumConstants;
  private transient int[] counts;
  private transient int distinctElements;
  private transient long size;

  /** Creates an empty {@code EnumMultiset}. */
  private EnumMultiset(Class<E> type) {
    this.type = type;

            

Reported by PMD.

Field size has the same name as a method
Error

Line: 88

                private transient E[] enumConstants;
  private transient int[] counts;
  private transient int distinctElements;
  private transient long size;

  /** Creates an empty {@code EnumMultiset}. */
  private EnumMultiset(Class<E> type) {
    this.type = type;
    checkArgument(type.isEnum());

            

Reported by PMD.

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

Line: 101

                private boolean isActuallyE(@CheckForNull Object o) {
    if (o instanceof Enum) {
      Enum<?> e = (Enum<?>) o;
      int index = e.ordinal();
      return index < enumConstants.length && enumConstants[index] == e;
    }
    return false;
  }


            

Reported by PMD.

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

Line: 135

                    return 0;
    }
    Enum<?> e = (Enum<?>) element;
    return counts[e.ordinal()];
  }

  // Modification Operations
  @CanIgnoreReturnValue
  @Override

            

Reported by PMD.

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

Line: 172

                  if (occurrences == 0) {
      return count(element);
    }
    int index = e.ordinal();
    int oldCount = counts[index];
    if (oldCount == 0) {
      return 0;
    } else if (oldCount <= occurrences) {
      counts[index] = 0;

            

Reported by PMD.

Avoid using redundant field initializer for 'index'
Performance

Line: 213

                }

  abstract class Itr<T> implements Iterator<T> {
    int index = 0;
    int toRemove = -1;

    abstract T output(int index);

    @Override

            

Reported by PMD.

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

Line: 213

                }

  abstract class Itr<T> implements Iterator<T> {
    int index = 0;
    int toRemove = -1;

    abstract T output(int index);

    @Override

            

Reported by PMD.

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

Line: 214

              
  abstract class Itr<T> implements Iterator<T> {
    int index = 0;
    int toRemove = -1;

    abstract T output(int index);

    @Override
    public boolean hasNext() {

            

Reported by PMD.

guava/src/com/google/common/collect/ForwardingSortedMap.java
11 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 69

                @Override
  @CheckForNull
  public Comparator<? super K> comparator() {
    return delegate().comparator();
  }

  @Override
  @ParametricNullness
  public K firstKey() {

            

Reported by PMD.

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

Line: 75

                @Override
  @ParametricNullness
  public K firstKey() {
    return delegate().firstKey();
  }

  @Override
  public SortedMap<K, V> headMap(@ParametricNullness K toKey) {
    return delegate().headMap(toKey);

            

Reported by PMD.

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

Line: 80

              
  @Override
  public SortedMap<K, V> headMap(@ParametricNullness K toKey) {
    return delegate().headMap(toKey);
  }

  @Override
  @ParametricNullness
  public K lastKey() {

            

Reported by PMD.

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

Line: 86

                @Override
  @ParametricNullness
  public K lastKey() {
    return delegate().lastKey();
  }

  @Override
  public SortedMap<K, V> subMap(@ParametricNullness K fromKey, @ParametricNullness K toKey) {
    return delegate().subMap(fromKey, toKey);

            

Reported by PMD.

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

Line: 91

              
  @Override
  public SortedMap<K, V> subMap(@ParametricNullness K fromKey, @ParametricNullness K toKey) {
    return delegate().subMap(fromKey, toKey);
  }

  @Override
  public SortedMap<K, V> tailMap(@ParametricNullness K fromKey) {
    return delegate().tailMap(fromKey);

            

Reported by PMD.

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

Line: 96

              
  @Override
  public SortedMap<K, V> tailMap(@ParametricNullness K fromKey) {
    return delegate().tailMap(fromKey);
  }

  /**
   * A sensible implementation of {@link SortedMap#keySet} in terms of the methods of {@code
   * ForwardingSortedMap}. In many cases, you may wish to override {@link

            

Reported by PMD.

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

Line: 139

                    // any CCE or NPE will be caught
      @SuppressWarnings({"unchecked", "nullness"})
      SortedMap<@Nullable Object, V> self = (SortedMap<@Nullable Object, V>) this;
      Object ceilingKey = self.tailMap(key).firstKey();
      return unsafeCompare(comparator(), ceilingKey, key) == 0;
    } catch (ClassCastException | NoSuchElementException | NullPointerException e) {
      return false;
    }
  }

            

Reported by PMD.

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

Line: 139

                    // any CCE or NPE will be caught
      @SuppressWarnings({"unchecked", "nullness"})
      SortedMap<@Nullable Object, V> self = (SortedMap<@Nullable Object, V>) this;
      Object ceilingKey = self.tailMap(key).firstKey();
      return unsafeCompare(comparator(), ceilingKey, key) == 0;
    } catch (ClassCastException | NoSuchElementException | NullPointerException e) {
      return false;
    }
  }

            

Reported by PMD.

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

Line: 141

                    SortedMap<@Nullable Object, V> self = (SortedMap<@Nullable Object, V>) this;
      Object ceilingKey = self.tailMap(key).firstKey();
      return unsafeCompare(comparator(), ceilingKey, key) == 0;
    } catch (ClassCastException | NoSuchElementException | NullPointerException e) {
      return false;
    }
  }

  /**

            

Reported by PMD.

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

Line: 141

                    SortedMap<@Nullable Object, V> self = (SortedMap<@Nullable Object, V>) this;
      Object ceilingKey = self.tailMap(key).firstKey();
      return unsafeCompare(comparator(), ceilingKey, key) == 0;
    } catch (ClassCastException | NoSuchElementException | NullPointerException e) {
      return false;
    }
  }

  /**

            

Reported by PMD.

guava/src/com/google/common/collect/TreeTraverser.java
11 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 132

                        @Override
          public void accept(T t) {
            action.accept(t);
            children(t).forEach(this);
          }
        }.accept(root);
      }
    };
  }

            

Reported by PMD.

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

Line: 144

                }

  private final class PreOrderIterator extends UnmodifiableIterator<T> {
    private final Deque<Iterator<T>> stack;

    PreOrderIterator(T root) {
      this.stack = new ArrayDeque<>();
      stack.addLast(Iterators.singletonIterator(checkNotNull(root)));
    }

            

Reported by PMD.

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

Line: 163

                    if (!itr.hasNext()) {
        stack.removeLast();
      }
      Iterator<T> childItr = children(result).iterator();
      if (childItr.hasNext()) {
        stack.addLast(childItr);
      }
      return result;
    }

            

Reported by PMD.

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

Line: 196

                      new Consumer<T>() {
          @Override
          public void accept(T t) {
            children(t).forEach(this);
            action.accept(t);
          }
        }.accept(root);
      }
    };

            

Reported by PMD.

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

Line: 209

                }

  private static final class PostOrderNode<T> {
    final T root;
    final Iterator<T> childIterator;

    PostOrderNode(T root, Iterator<T> childIterator) {
      this.root = checkNotNull(root);
      this.childIterator = checkNotNull(childIterator);

            

Reported by PMD.

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

Line: 210

              
  private static final class PostOrderNode<T> {
    final T root;
    final Iterator<T> childIterator;

    PostOrderNode(T root, Iterator<T> childIterator) {
      this.root = checkNotNull(root);
      this.childIterator = checkNotNull(childIterator);
    }

            

Reported by PMD.

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

Line: 219

                }

  private final class PostOrderIterator extends AbstractIterator<T> {
    private final ArrayDeque<PostOrderNode<T>> stack;

    PostOrderIterator(T root) {
      this.stack = new ArrayDeque<>();
      stack.addLast(expand(root));
    }

            

Reported by PMD.

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

Line: 231

                  protected T computeNext() {
      while (!stack.isEmpty()) {
        PostOrderNode<T> top = stack.getLast();
        if (top.childIterator.hasNext()) {
          T child = top.childIterator.next();
          stack.addLast(expand(child));
        } else {
          stack.removeLast();
          return top.root;

            

Reported by PMD.

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

Line: 232

                    while (!stack.isEmpty()) {
        PostOrderNode<T> top = stack.getLast();
        if (top.childIterator.hasNext()) {
          T child = top.childIterator.next();
          stack.addLast(expand(child));
        } else {
          stack.removeLast();
          return top.root;
        }

            

Reported by PMD.

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

Line: 243

                  }

    private PostOrderNode<T> expand(T t) {
      return new PostOrderNode<T>(t, children(t).iterator());
    }
  }

  /**
   * Returns an unmodifiable iterable over the nodes in a tree structure, using breadth-first

            

Reported by PMD.

guava/src/com/google/common/hash/Crc32cHashFunction.java
11 issues
Avoid reassigning parameters such as 'csum'
Design

Line: 364

                        ^ STRIDE_TABLE[0][word >>> 24];
    }

    static int combine(int csum, int crc) {
      csum ^= crc;
      for (int i = 0; i < 4; i++) {
        csum = (csum >>> 8) ^ BYTE_TABLE[csum & 0xFF];
      }
      return csum;

            

Reported by PMD.

Avoid reassigning parameters such as 'csum'
Design

Line: 364

                        ^ STRIDE_TABLE[0][word >>> 24];
    }

    static int combine(int csum, int crc) {
      csum ^= crc;
      for (int i = 0; i < 4; i++) {
        csum = (csum >>> 8) ^ BYTE_TABLE[csum & 0xFF];
      }
      return csum;

            

Reported by PMD.

Avoid using redundant field initializer for 'finished'
Performance

Line: 63

                    super(16);
    }

    private boolean finished = false;

    /*
     * This trick allows us to avoid having separate states for "first four ints" and "all other
     * four int chunks."  The state we want after the first four bytes is
     *

            

Reported by PMD.

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

Line: 63

                    super(16);
    }

    private boolean finished = false;

    /*
     * This trick allows us to avoid having separate states for "first four ints" and "all other
     * four int chunks."  The state we want after the first four bytes is
     *

            

Reported by PMD.

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

Line: 77

                   * ...so we set crc0 so that computeForWord(crc0) = -1 and xoring it with the first int
     * gives us the desired result.  computeForWord(0) == 0, so all the others do the right thing.
     */
    private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override

            

Reported by PMD.

Avoid using redundant field initializer for 'crc1'
Performance

Line: 78

                   * gives us the desired result.  computeForWord(0) == 0, so all the others do the right thing.
     */
    private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override
    protected void process(ByteBuffer bb) {

            

Reported by PMD.

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

Line: 78

                   * gives us the desired result.  computeForWord(0) == 0, so all the others do the right thing.
     */
    private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override
    protected void process(ByteBuffer bb) {

            

Reported by PMD.

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

Line: 79

                   */
    private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override
    protected void process(ByteBuffer bb) {
      if (finished) {

            

Reported by PMD.

Avoid using redundant field initializer for 'crc2'
Performance

Line: 79

                   */
    private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override
    protected void process(ByteBuffer bb) {
      if (finished) {

            

Reported by PMD.

Avoid using redundant field initializer for 'crc3'
Performance

Line: 80

                  private int crc0 = INVERSE_COMPUTE_FOR_WORD_OF_ALL_1S;
    private int crc1 = 0;
    private int crc2 = 0;
    private int crc3 = 0;

    @Override
    protected void process(ByteBuffer bb) {
      if (finished) {
        throw new IllegalStateException(

            

Reported by PMD.