The following issues were found

guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java
17 issues
Class cannot be instantiated and does not provide any static methods or fields
Error

Line: 42

               * @author Louis Wasserman
 */
@GwtCompatible
public final class DerivedGoogleCollectionGenerators {
  public static class MapGenerator<K, V> implements TestMapGenerator<K, V>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public MapGenerator(

            

Reported by PMD.

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

Line: 45

              public final class DerivedGoogleCollectionGenerators {
  public static class MapGenerator<K, V> implements TestMapGenerator<K, V>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public MapGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
      this.generator = oneSizeTestContainerGenerator;
    }

            

Reported by PMD.

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

Line: 72

                    return generator.order(insertionOrder);
    }

    @SuppressWarnings("unchecked")
    @Override
    public K[] createKeyArray(int length) {
      return (K[]) new Object[length];
    }


            

Reported by PMD.

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

Line: 93

                public static class InverseBiMapGenerator<K, V>
      implements TestBiMapGenerator<V, K>, DerivedGenerator {

    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;

    public InverseBiMapGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
      this.generator = oneSizeTestContainerGenerator;
    }

            

Reported by PMD.

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

Line: 104

                  public SampleElements<Entry<V, K>> samples() {
      SampleElements<Entry<K, V>> samples = generator.samples();
      return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

            

Reported by PMD.

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

Line: 105

                    SampleElements<Entry<K, V>> samples = generator.samples();
      return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }


            

Reported by PMD.

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

Line: 106

                    return new SampleElements<>(
          reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {

            

Reported by PMD.

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

Line: 107

                        reverse(samples.e0()),
          reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {
      return Helpers.mapEntry(entry.getValue(), entry.getKey());

            

Reported by PMD.

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

Line: 108

                        reverse(samples.e1()),
          reverse(samples.e2()),
          reverse(samples.e3()),
          reverse(samples.e4()));
    }

    private Entry<V, K> reverse(Entry<K, V> entry) {
      return Helpers.mapEntry(entry.getValue(), entry.getKey());
    }

            

Reported by PMD.

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

Line: 156

              
  public static class BiMapValueSetGenerator<K, V>
      implements TestSetGenerator<V>, DerivedGenerator {
    private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator;
    private final SampleElements<V> samples;

    public BiMapValueSetGenerator(
        OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator) {
      this.mapGenerator = mapGenerator;

            

Reported by PMD.

android/guava/src/com/google/common/collect/ObjectArrays.java
17 issues
Avoid throwing null pointer exceptions.
Design

Line: 231

                @CanIgnoreReturnValue
  static Object checkElementNotNull(@CheckForNull Object element, int index) {
    if (element == null) {
      throw new NullPointerException("at index " + index);
    }
    return element;
  }
}

            

Reported by PMD.

Avoid reassigning parameters such as 'array'
Design

Line: 129

                 * @throws ArrayStoreException if the runtime type of the specified array is not a supertype of
   *     the runtime type of every element in the specified collection
   */
  static <T extends @Nullable Object> T[] toArrayImpl(Collection<?> c, T[] array) {
    int size = c.size();
    if (array.length < size) {
      array = newArray(array, size);
    }
    fillArray(c, array);

            

Reported by PMD.

Avoid reassigning parameters such as 'dst'
Design

Line: 154

                 * <i>only</i> if the caller knows that the collection does not contain any null elements.
   */
  static <T extends @Nullable Object> T[] toArrayImpl(
      @Nullable Object[] src, int offset, int len, T[] dst) {
    checkPositionIndexes(offset, offset + len, src.length);
    if (dst.length < len) {
      dst = newArray(dst, len);
    } else if (dst.length > len) {
      @Nullable Object[] unsoundlyCovariantArray = dst;

            

Reported by PMD.

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

Line: 38

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

  private ObjectArrays() {}

  /**
   * Returns a new array of the given length with the specified component type.

            

Reported by PMD.

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

Line: 137

                  fillArray(c, array);
    if (array.length > size) {
      @Nullable Object[] unsoundlyCovariantArray = array;
      unsoundlyCovariantArray[size] = null;
    }
    return array;
  }

  /**

            

Reported by PMD.

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

Line: 160

                    dst = newArray(dst, len);
    } else if (dst.length > len) {
      @Nullable Object[] unsoundlyCovariantArray = dst;
      unsoundlyCovariantArray[len] = null;
    }
    System.arraycopy(src, offset, dst, 0, len);
    return dst;
  }


            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 87

                 * @return an array whose size is one larger than {@code array}, with {@code element} occupying
   *     the first position, and the elements of {@code array} occupying the remaining elements.
   */
  public static <T extends @Nullable Object> T[] concat(@ParametricNullness T element, T[] array) {
    T[] result = newArray(array, array.length + 1);
    result[0] = element;
    System.arraycopy(array, 0, result, 1, array.length);
    return result;
  }

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 129

                 * @throws ArrayStoreException if the runtime type of the specified array is not a supertype of
   *     the runtime type of every element in the specified collection
   */
  static <T extends @Nullable Object> T[] toArrayImpl(Collection<?> c, T[] array) {
    int size = c.size();
    if (array.length < size) {
      array = newArray(array, size);
    }
    fillArray(c, array);

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 154

                 * <i>only</i> if the caller knows that the collection does not contain any null elements.
   */
  static <T extends @Nullable Object> T[] toArrayImpl(
      @Nullable Object[] src, int offset, int len, T[] dst) {
    checkPositionIndexes(offset, offset + len, src.length);
    if (dst.length < len) {
      dst = newArray(dst, len);
    } else if (dst.length > len) {
      @Nullable Object[] unsoundlyCovariantArray = dst;

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 197

                }

  @CanIgnoreReturnValue
  private static @Nullable Object[] fillArray(Iterable<?> elements, @Nullable Object[] array) {
    int i = 0;
    for (Object element : elements) {
      array[i++] = element;
    }
    return array;

            

Reported by PMD.

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

Line: 78

                private final int port;

  /** True if the parsed host has colons, but no surrounding brackets. */
  private final boolean hasBracketlessColons;

  private HostAndPort(String host, int port, boolean hasBracketlessColons) {
    this.host = host;
    this.port = port;
    this.hasBracketlessColons = hasBracketlessColons;

            

Reported by PMD.

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

Line: 136

                public static HostAndPort fromParts(String host, int port) {
    checkArgument(isValidPort(port), "Port out of range: %s", port);
    HostAndPort parsedHost = fromString(host);
    checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host);
    return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons);
  }

  /**
   * Build a HostAndPort instance from a host only.

            

Reported by PMD.

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

Line: 153

                 */
  public static HostAndPort fromHost(String host) {
    HostAndPort parsedHost = fromString(host);
    checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host);
    return parsedHost;
  }

  /**
   * Split a freeform string into a host and port, without strict validation.

            

Reported by PMD.

This call to String.startsWith can be rewritten using String.charAt(0)
Performance

Line: 173

                  String portString = null;
    boolean hasBracketlessColons = false;

    if (hostPortString.startsWith("[")) {
      String[] hostAndPort = getHostAndPortFromBracketedHost(hostPortString);
      host = hostAndPort[0];
      portString = hostAndPort[1];
    } else {
      int colonPos = hostPortString.indexOf(':');

            

Reported by PMD.

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

Line: 195

                    // Try to parse the whole port string as a number.
      // JDK7 accepts leading plus signs. We don't want to.
      checkArgument(
          !portString.startsWith("+") && CharMatcher.ascii().matchesAllOf(portString),
          "Unparseable port number: %s",
          hostPortString);
      try {
        port = Integer.parseInt(portString);
      } catch (NumberFormatException e) {

            

Reported by PMD.

This call to String.startsWith can be rewritten using String.charAt(0)
Performance

Line: 195

                    // Try to parse the whole port string as a number.
      // JDK7 accepts leading plus signs. We don't want to.
      checkArgument(
          !portString.startsWith("+") && CharMatcher.ascii().matchesAllOf(portString),
          "Unparseable port number: %s",
          hostPortString);
      try {
        port = Integer.parseInt(portString);
      } catch (NumberFormatException e) {

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 201

                    try {
        port = Integer.parseInt(portString);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Unparseable port number: " + hostPortString);
      }
      checkArgument(isValidPort(port), "Port number out of range: %s", hostPortString);
    }

    return new HostAndPort(host, port, hasBracketlessColons);

            

Reported by PMD.

Found 'DD'-anomaly for variable 'portString' (lines '170'-'182').
Error

Line: 170

                public static HostAndPort fromString(String hostPortString) {
    checkNotNull(hostPortString);
    String host;
    String portString = null;
    boolean hasBracketlessColons = false;

    if (hostPortString.startsWith("[")) {
      String[] hostAndPort = getHostAndPortFromBracketedHost(hostPortString);
      host = hostAndPort[0];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'portString' (lines '170'-'176').
Error

Line: 170

                public static HostAndPort fromString(String hostPortString) {
    checkNotNull(hostPortString);
    String host;
    String portString = null;
    boolean hasBracketlessColons = false;

    if (hostPortString.startsWith("[")) {
      String[] hostAndPort = getHostAndPortFromBracketedHost(hostPortString);
      host = hostAndPort[0];

            

Reported by PMD.

Found 'DU'-anomaly for variable 'hasBracketlessColons' (lines '171'-'207').
Error

Line: 171

                  checkNotNull(hostPortString);
    String host;
    String portString = null;
    boolean hasBracketlessColons = false;

    if (hostPortString.startsWith("[")) {
      String[] hostAndPort = getHostAndPortFromBracketedHost(hostPortString);
      host = hostAndPort[0];
      portString = hostAndPort[1];

            

Reported by PMD.

android/guava/src/com/google/common/base/internal/Finalizer.java
17 issues
A class which only has private constructors should be final
Design

Line: 46

               * collected, and this class can detect when the main class loader has been garbage collected and
 * stop itself.
 */
public class Finalizer implements Runnable {

  private static final Logger logger = Logger.getLogger(Finalizer.class.getName());

  /** Name of FinalizableReference.class. */
  private static final String FINALIZABLE_REFERENCE = "com.google.common.base.FinalizableReference";

            

Reported by PMD.

Avoid reassigning parameters such as 'reference'
Design

Line: 161

                 * @return true if the caller should continue, false if the associated FinalizableReferenceQueue
   *     is no longer referenced.
   */
  private boolean cleanUp(Reference<?> reference) {
    Method finalizeReferentMethod = getFinalizeReferentMethod();
    if (finalizeReferentMethod == null) {
      return false;
    }
    do {

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 221

                    inheritableThreadLocals.setAccessible(true);
      return inheritableThreadLocals;
    } catch (Throwable t) {
      logger.log(
          Level.INFO,
          "Couldn't access Thread.inheritableThreadLocals. Reference finalizer threads will "
              + "inherit thread local values.");
      return null;
    }

            

Reported by PMD.

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

Line: 74

                   * 2) To detect when FinalizableReference's class loader has to be garbage collected, at which
     * point, Finalizer can stop running
     */
    if (!finalizableReferenceClass.getName().equals(FINALIZABLE_REFERENCE)) {
      throw new IllegalArgumentException("Expected " + FINALIZABLE_REFERENCE + ".");
    }

    Finalizer finalizer = new Finalizer(finalizableReferenceClass, queue, frqReference);
    String threadName = Finalizer.class.getName();

            

Reported by PMD.

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

Line: 88

                      thread =
            bigThreadConstructor.newInstance(
                (ThreadGroup) null, finalizer, threadName, defaultStackSize, inheritThreadLocals);
      } catch (Throwable t) {
        logger.log(
            Level.INFO, "Failed to create a thread without inherited thread-local values", t);
      }
    }
    if (thread == null) {

            

Reported by PMD.

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

Line: 102

                    if (inheritableThreadLocals != null) {
        inheritableThreadLocals.set(thread, null);
      }
    } catch (Throwable t) {
      logger.log(
          Level.INFO,
          "Failed to clear thread local values inherited by reference finalizer thread.",
          t);
    }

            

Reported by PMD.

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

Line: 112

                  thread.start();
  }

  private final WeakReference<Class<?>> finalizableReferenceClassReference;
  private final PhantomReference<Object> frqReference;
  private final ReferenceQueue<Object> queue;

  // By preference, we will use the Thread constructor that has an `inheritThreadLocals` parameter.
  // But before Java 9, our only way not to inherit ThreadLocals is to zap them after the thread

            

Reported by PMD.

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

Line: 113

                }

  private final WeakReference<Class<?>> finalizableReferenceClassReference;
  private final PhantomReference<Object> frqReference;
  private final ReferenceQueue<Object> queue;

  // By preference, we will use the Thread constructor that has an `inheritThreadLocals` parameter.
  // But before Java 9, our only way not to inherit ThreadLocals is to zap them after the thread
  // is created, by accessing a private field.

            

Reported by PMD.

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

Line: 114

              
  private final WeakReference<Class<?>> finalizableReferenceClassReference;
  private final PhantomReference<Object> frqReference;
  private final ReferenceQueue<Object> queue;

  // By preference, we will use the Thread constructor that has an `inheritThreadLocals` parameter.
  // But before Java 9, our only way not to inherit ThreadLocals is to zap them after the thread
  // is created, by accessing a private field.
  @NullableDecl

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 173

                     */
      reference.clear();

      if (reference == frqReference) {
        /*
         * The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
         */
        return false;
      }

            

Reported by PMD.

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

Line: 69

                      + " GraphBuilder)")
@ElementTypesAreNonnullByDefault
public abstract class Traverser<N> {
  private final SuccessorsFunction<N> successorFunction;

  private Traverser(SuccessorsFunction<N> successorFunction) {
    this.successorFunction = checkNotNull(successorFunction);
  }


            

Reported by PMD.

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

Line: 246

                  return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().breadthFirst(validated.iterator());
      }
    };
  }

  /**

            

Reported by PMD.

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

Line: 301

                  return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().preOrder(validated.iterator());
      }
    };
  }

  /**

            

Reported by PMD.

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

Line: 356

                  return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().postOrder(validated.iterator());
      }
    };
  }

  abstract Traversal<N> newTraversal();

            

Reported by PMD.

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

Line: 378

                 * non-empty iterator to find first unvisited node.
   */
  private abstract static class Traversal<N> {
    final SuccessorsFunction<N> successorFunction;

    Traversal(SuccessorsFunction<N> successorFunction) {
      this.successorFunction = successorFunction;
    }


            

Reported by PMD.

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

Line: 451

                        do {
            N next = visitNext(horizon);
            if (next != null) {
              Iterator<? extends N> successors = successorFunction.successors(next).iterator();
              if (successors.hasNext()) {
                // BFS: horizon.addLast(successors)
                // Pre-order: horizon.addFirst(successors)
                order.insertInto(horizon, successors);
              }

            

Reported by PMD.

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

Line: 474

                      @CheckForNull
        protected N computeNext() {
          for (N next = visitNext(horizon); next != null; next = visitNext(horizon)) {
            Iterator<? extends N> successors = successorFunction.successors(next).iterator();
            if (!successors.hasNext()) {
              return next;
            }
            horizon.addFirst(successors);
            ancestorStack.push(next);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'validated' (lines '242'-'249').
Error

Line: 242

                 * @since 24.1
   */
  public final Iterable<N> breadthFirst(Iterable<? extends N> startNodes) {
    final ImmutableSet<N> validated = validate(startNodes);
    return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().breadthFirst(validated.iterator());
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'validated' (lines '242'-'249').
Error

Line: 242

                 * @since 24.1
   */
  public final Iterable<N> breadthFirst(Iterable<? extends N> startNodes) {
    final ImmutableSet<N> validated = validate(startNodes);
    return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().breadthFirst(validated.iterator());
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'validated' (lines '297'-'304').
Error

Line: 297

                 * @since 24.1
   */
  public final Iterable<N> depthFirstPreOrder(Iterable<? extends N> startNodes) {
    final ImmutableSet<N> validated = validate(startNodes);
    return new Iterable<N>() {
      @Override
      public Iterator<N> iterator() {
        return newTraversal().preOrder(validated.iterator());
      }

            

Reported by PMD.

guava-gwt/src-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/AbstractFuture.java
17 issues
Logger calls should be surrounded by log level guards.
Design

Line: 375

                    try {
        executor.execute(command);
      } catch (RuntimeException e) {
        log.log(
            Level.SEVERE,
            "RuntimeException while executing runnable " + command + " with executor " + executor,
            e);
      }
    }

            

Reported by PMD.

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

Line: 41

              /** Emulation for AbstractFuture in GWT. */
@SuppressWarnings("nullness") // TODO(b/147136275): Remove once our checker understands & and |.
public abstract class AbstractFuture<V> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {

  /**
   * Tag interface marking trusted subclasses. This enables some optimizations. The implementation
   * of this interface must also be an AbstractFuture and must not override or expose for overriding
   * any of the public methods of ListenableFuture.

            

Reported by PMD.

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

Line: 85

              
  private static final Logger log = Logger.getLogger(AbstractFuture.class.getName());

  private State state;
  private V value;
  private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;

            

Reported by PMD.

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

Line: 86

                private static final Logger log = Logger.getLogger(AbstractFuture.class.getName());

  private State state;
  private V value;
  private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;


            

Reported by PMD.

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

Line: 87

              
  private State state;
  private V value;
  private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;

  protected AbstractFuture() {

            

Reported by PMD.

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

Line: 88

                private State state;
  private V value;
  private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;

  protected AbstractFuture() {
    state = State.PENDING;

            

Reported by PMD.

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

Line: 89

                private V value;
  private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;

  protected AbstractFuture() {
    state = State.PENDING;
    listeners = new ArrayList<Listener>();

            

Reported by PMD.

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

Line: 90

                private Future<? extends V> delegate;
  private Throwable throwable;
  private boolean mayInterruptIfRunning;
  private List<Listener> listeners;

  protected AbstractFuture() {
    state = State.PENDING;
    listeners = new ArrayList<Listener>();
  }

            

Reported by PMD.

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

Line: 216

                  for (Listener listener : listeners) {
      listener.execute();
    }
    listeners = null;
  }

  protected void afterDone() {}

  @Override

            

Reported by PMD.

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

Line: 251

                    String pendingDescription;
      try {
        pendingDescription = pendingToString();
      } catch (RuntimeException e) {
        // Don't call getMessage or toString() on the exception, in case the exception thrown by the
        // subclass is implemented with bugs similar to the subclass.
        pendingDescription = "Exception thrown from implementation: " + e.getClass();
      }
      // The future may complete during or before the call to getPendingToString, so we use null

            

Reported by PMD.

android/guava/src/com/google/common/hash/Hashing.java
17 issues
This class has too many methods, consider refactoring it.
Design

Line: 47

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class Hashing {
  /**
   * Returns a general-purpose, <b>temporary-use</b>, non-cryptographic hash function. The algorithm
   * the returned function implements is unspecified and subject to change without notice.
   *
   * <p><b>Warning:</b> a new random seed for these functions is chosen each time the {@code

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 68

                public static HashFunction goodFastHash(int minimumBits) {
    int bits = checkPositiveAndMakeMultipleOf32(minimumBits);

    if (bits == 32) {
      return Murmur3_32HashFunction.GOOD_FAST_HASH_32;
    }
    if (bits <= 128) {
      return Murmur3_128HashFunction.GOOD_FAST_HASH_128;
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 71

                  if (bits == 32) {
      return Murmur3_32HashFunction.GOOD_FAST_HASH_32;
    }
    if (bits <= 128) {
      return Murmur3_128HashFunction.GOOD_FAST_HASH_128;
    }

    // Otherwise, join together some 128-bit murmur3s
    int hashFunctionsNeeded = (bits + 127) / 128;

            

Reported by PMD.

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

Line: 519

                public static HashCode combineOrdered(Iterable<HashCode> hashCodes) {
    Iterator<HashCode> iterator = hashCodes.iterator();
    checkArgument(iterator.hasNext(), "Must be at least 1 hash code to combine.");
    int bits = iterator.next().bits();
    byte[] resultBytes = new byte[bits / 8];
    for (HashCode hashCode : hashCodes) {
      byte[] nextBytes = hashCode.asBytes();
      checkArgument(
          nextBytes.length == resultBytes.length, "All hashcodes must have the same bit length.");

            

Reported by PMD.

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

Line: 544

                public static HashCode combineUnordered(Iterable<HashCode> hashCodes) {
    Iterator<HashCode> iterator = hashCodes.iterator();
    checkArgument(iterator.hasNext(), "Must be at least 1 hash code to combine.");
    byte[] resultBytes = new byte[iterator.next().bits() / 8];
    for (HashCode hashCode : hashCodes) {
      byte[] nextBytes = hashCode.asBytes();
      checkArgument(
          nextBytes.length == resultBytes.length, "All hashcodes must have the same bit length.");
      for (int i = 0; i < nextBytes.length; i++) {

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 599

                  for (HashFunction hashFunction : hashFunctions) {
      list.add(hashFunction);
    }
    checkArgument(list.size() > 0, "number of hash functions (%s) must be > 0", list.size());
    return new ConcatenatedHashFunction(list.toArray(new HashFunction[0]));
  }

  private static final class ConcatenatedHashFunction extends AbstractCompositeHashFunction {


            

Reported by PMD.

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

Line: 622

                    int i = 0;
      for (Hasher hasher : hashers) {
        HashCode newHash = hasher.hash();
        i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8);
      }
      return HashCode.fromBytesNoCopy(bytes);
    }

    @Override

            

Reported by PMD.

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

Line: 622

                    int i = 0;
      for (Hasher hasher : hashers) {
        HashCode newHash = hasher.hash();
        i += newHash.writeBytesTo(bytes, i, newHash.bits() / 8);
      }
      return HashCode.fromBytesNoCopy(bytes);
    }

    @Override

            

Reported by PMD.

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

Line: 656

                 * http://en.wikipedia.org/wiki/Linear_congruential_generator
   */
  private static final class LinearCongruentialGenerator {
    private long state;

    public LinearCongruentialGenerator(long seed) {
      this.state = seed;
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'hashFunctions' (lines '77'-'78').
Error

Line: 77

              
    // Otherwise, join together some 128-bit murmur3s
    int hashFunctionsNeeded = (bits + 127) / 128;
    HashFunction[] hashFunctions = new HashFunction[hashFunctionsNeeded];
    hashFunctions[0] = Murmur3_128HashFunction.GOOD_FAST_HASH_128;
    int seed = GOOD_FAST_HASH_SEED;
    for (int i = 1; i < hashFunctionsNeeded; i++) {
      seed += 1500450271; // a prime; shouldn't matter
      hashFunctions[i] = murmur3_128(seed);

            

Reported by PMD.

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

Line: 39

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper

            

Reported by PMD.

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

Line: 40

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 41

              public abstract class AbstractContainerTester<C, E>
    extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
  protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  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: 43

                protected SampleElements<E> samples;
  protected C container;

  @Override
  @OverridingMethodsMustInvokeSuper
  public void setUp() throws Exception {
    super.setUp();
    samples = this.getSubjectGenerator().samples();
    resetContainer();

            

Reported by PMD.

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

Line: 65

                 * @return the new container instance.
   */
  protected C resetContainer() {
    return resetContainer(getSubjectGenerator().createTestSubject());
  }

  /**
   * Replaces the existing container under test with a new container. This is useful when a single
   * test method needs to create multiple containers while retaining the ability to use {@link

            

Reported by PMD.

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

Line: 136

                 */
  protected final void expectAdded(E... elements) {
    List<E> expected = Helpers.copyToList(getSampleElements());
    expected.addAll(Arrays.asList(elements));
    expectContents(expected);
  }

  protected final void expectAdded(int index, E... elements) {
    expectAdded(index, Arrays.asList(elements));

            

Reported by PMD.

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

Line: 146

              
  protected final void expectAdded(int index, Collection<E> elements) {
    List<E> expected = Helpers.copyToList(getSampleElements());
    expected.addAll(index, elements);
    expectContents(expected);
  }

  /*
   * TODO: if we're testing a list, we could check indexOf(). (Doing it in

            

Reported by PMD.

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

Line: 158

                 */
  protected void expectMissing(E... elements) {
    for (E element : elements) {
      assertFalse("Should not contain " + element, actualContents().contains(element));
    }
  }

  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());

            

Reported by PMD.

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

Line: 163

                }

  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());
    getSampleElements().toArray(array);
    return array;
  }

  protected E[] createOrderedArray() {

            

Reported by PMD.

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

Line: 164

              
  protected E[] createSamplesArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());
    getSampleElements().toArray(array);
    return array;
  }

  protected E[] createOrderedArray() {
    E[] array = getSubjectGenerator().createArray(getNumElements());

            

Reported by PMD.

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

Line: 43

                    new SipHashFunction(2, 4, 0x0706050403020100L, 0x0f0e0d0c0b0a0908L);

  // The number of compression rounds.
  private final int c;
  // The number of finalization rounds.
  private final int d;
  // Two 64-bit keys (represent a single 128-bit key).
  private final long k0;
  private final long k1;

            

Reported by PMD.

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

Line: 45

                // The number of compression rounds.
  private final int c;
  // The number of finalization rounds.
  private final int d;
  // Two 64-bit keys (represent a single 128-bit key).
  private final long k0;
  private final long k1;

  /**

            

Reported by PMD.

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

Line: 47

                // The number of finalization rounds.
  private final int d;
  // Two 64-bit keys (represent a single 128-bit key).
  private final long k0;
  private final long k1;

  /**
   * @param c the number of compression rounds (must be positive)
   * @param d the number of finalization rounds (must be positive)

            

Reported by PMD.

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

Line: 48

                private final int d;
  // Two 64-bit keys (represent a single 128-bit key).
  private final long k0;
  private final long k1;

  /**
   * @param c the number of compression rounds (must be positive)
   * @param d the number of finalization rounds (must be positive)
   * @param k0 the first half of the key

            

Reported by PMD.

Do not add empty strings
Performance

Line: 81

              
  @Override
  public String toString() {
    return "Hashing.sipHash" + c + "" + d + "(" + k0 + ", " + k1 + ")";
  }

  @Override
  public boolean equals(@CheckForNull Object object) {
    if (object instanceof SipHashFunction) {

            

Reported by PMD.

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

Line: 95

              
  @Override
  public int hashCode() {
    return (int) (getClass().hashCode() ^ c ^ d ^ k0 ^ k1);
  }

  private static final class SipHasher extends AbstractStreamingHasher {
    private static final int CHUNK_SIZE = 8;


            

Reported by PMD.

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

Line: 102

                  private static final int CHUNK_SIZE = 8;

    // The number of compression rounds.
    private final int c;
    // The number of finalization rounds.
    private final int d;

    // Four 64-bit words of internal state.
    // The initial state corresponds to the ASCII string "somepseudorandomlygeneratedbytes",

            

Reported by PMD.

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

Line: 104

                  // The number of compression rounds.
    private final int c;
    // The number of finalization rounds.
    private final int d;

    // Four 64-bit words of internal state.
    // The initial state corresponds to the ASCII string "somepseudorandomlygeneratedbytes",
    // big-endian encoded. There is nothing special about this value; the only requirement
    // was some asymmetry so that the initial v0 and v1 differ from v2 and v3.

            

Reported by PMD.

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

Line: 110

                  // The initial state corresponds to the ASCII string "somepseudorandomlygeneratedbytes",
    // big-endian encoded. There is nothing special about this value; the only requirement
    // was some asymmetry so that the initial v0 and v1 differ from v2 and v3.
    private long v0 = 0x736f6d6570736575L;
    private long v1 = 0x646f72616e646f6dL;
    private long v2 = 0x6c7967656e657261L;
    private long v3 = 0x7465646279746573L;

    // The number of bytes in the input.

            

Reported by PMD.

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

Line: 111

                  // big-endian encoded. There is nothing special about this value; the only requirement
    // was some asymmetry so that the initial v0 and v1 differ from v2 and v3.
    private long v0 = 0x736f6d6570736575L;
    private long v1 = 0x646f72616e646f6dL;
    private long v2 = 0x6c7967656e657261L;
    private long v3 = 0x7465646279746573L;

    // The number of bytes in the input.
    private long b = 0;

            

Reported by PMD.

guava-tests/test/com/google/common/net/HttpHeadersTest.java
17 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: 36

               */
public class HttpHeadersTest extends TestCase {

  public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.

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

Line: 39

                public void testConstantNameMatchesString() throws Exception {
    // Special case some of the weird HTTP Header names...
    ImmutableBiMap<String, String> specialCases =
        ImmutableBiMap.<String, String>builder()
            .put("CDN_LOOP", "CDN-Loop")
            .put("ETAG", "ETag")
            .put("SOURCE_MAP", "SourceMap")
            .put("SEC_WEBSOCKET_ACCEPT", "Sec-WebSocket-Accept")
            .put("SEC_WEBSOCKET_EXTENSIONS", "Sec-WebSocket-Extensions")

            

Reported by PMD.