The following issues were found

guava-gwt/test/com/google/common/GwtTestSuite.java
5 issues
This class name ends with Test but contains no test cases
Error

Line: 33

               * Runs all _gwt tests. Grouping them into a suite is much faster than running each as a one-test
 * "suite," as the per-suite setup is expensive.
 */
public class GwtTestSuite extends TestCase {
  public static Test suite() throws IOException {
    GWTTestSuite suite = new GWTTestSuite();
    for (ClassInfo info
        : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
      if (info.getName().endsWith("_gwt")) {

            

Reported by PMD.

JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 34

               * "suite," as the per-suite setup is expensive.
 */
public class GwtTestSuite extends TestCase {
  public static Test suite() throws IOException {
    GWTTestSuite suite = new GWTTestSuite();
    for (ClassInfo info
        : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
      if (info.getName().endsWith("_gwt")) {
        Class<?> clazz = info.load();

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 37

                public static Test suite() throws IOException {
    GWTTestSuite suite = new GWTTestSuite();
    for (ClassInfo info
        : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
      if (info.getName().endsWith("_gwt")) {
        Class<?> clazz = info.load();
        // TODO(cpovirk): why does asSubclass() throw? Is it something about ClassLoaders?
        @SuppressWarnings("unchecked")
        Class<? extends GWTTestCase> cast = (Class<? extends GWTTestCase>) clazz;

            

Reported by PMD.

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

Line: 37

                public static Test suite() throws IOException {
    GWTTestSuite suite = new GWTTestSuite();
    for (ClassInfo info
        : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
      if (info.getName().endsWith("_gwt")) {
        Class<?> clazz = info.load();
        // TODO(cpovirk): why does asSubclass() throw? Is it something about ClassLoaders?
        @SuppressWarnings("unchecked")
        Class<? extends GWTTestCase> cast = (Class<? extends GWTTestCase>) clazz;

            

Reported by PMD.

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

Line: 38

                  GWTTestSuite suite = new GWTTestSuite();
    for (ClassInfo info
        : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
      if (info.getName().endsWith("_gwt")) {
        Class<?> clazz = info.load();
        // TODO(cpovirk): why does asSubclass() throw? Is it something about ClassLoaders?
        @SuppressWarnings("unchecked")
        Class<? extends GWTTestCase> cast = (Class<? extends GWTTestCase>) clazz;
        suite.addTestSuite(cast);

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/FakeTimeLimiter.java
5 issues
Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 59

                  checkNotNull(timeoutUnit);
    try {
      return callable.call();
    } catch (RuntimeException e) {
      throw new UncheckedExecutionException(e);
    } catch (Exception e) {
      throw new ExecutionException(e);
    } catch (Error e) {
      throw new ExecutionError(e);

            

Reported by PMD.

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

Line: 61

                    return callable.call();
    } catch (RuntimeException e) {
      throw new UncheckedExecutionException(e);
    } catch (Exception e) {
      throw new ExecutionException(e);
    } catch (Error e) {
      throw new ExecutionError(e);
    } catch (Throwable e) {
      // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend

            

Reported by PMD.

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

Line: 65

                    throw new ExecutionException(e);
    } catch (Error e) {
      throw new ExecutionError(e);
    } catch (Throwable e) {
      // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend
      // Exception, so we'll treat it like an Exception.
      throw new ExecutionException(e);
    }
  }

            

Reported by PMD.

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

Line: 85

                  checkNotNull(timeoutUnit);
    try {
      runnable.run();
    } catch (RuntimeException e) {
      throw new UncheckedExecutionException(e);
    } catch (Error e) {
      throw new ExecutionError(e);
    } catch (Throwable e) {
      // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend

            

Reported by PMD.

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

Line: 89

                    throw new UncheckedExecutionException(e);
    } catch (Error e) {
      throw new ExecutionError(e);
    } catch (Throwable e) {
      // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend
      // Exception, so we'll treat it like a RuntimeException.
      throw new UncheckedExecutionException(e);
    }
  }

            

Reported by PMD.

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

Line: 36

              @ElementTypesAreNonnullByDefault
abstract class LineBuffer {
  /** Holds partial line contents. */
  private StringBuilder line = new StringBuilder();
  /** Whether a line ending with a CR is pending processing. */
  private boolean sawReturn;

  /**
   * Process additional characters from the stream. When a line separator is found the contents of

            

Reported by PMD.

StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).
Design

Line: 36

              @ElementTypesAreNonnullByDefault
abstract class LineBuffer {
  /** Holds partial line contents. */
  private StringBuilder line = new StringBuilder();
  /** Whether a line ending with a CR is pending processing. */
  private boolean sawReturn;

  /**
   * Process additional characters from the stream. When a line separator is found the contents of

            

Reported by PMD.

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

Line: 38

                /** Holds partial line contents. */
  private StringBuilder line = new StringBuilder();
  /** Whether a line ending with a CR is pending processing. */
  private boolean sawReturn;

  /**
   * Process additional characters from the stream. When a line separator is found the contents of
   * the line and the line separator itself are passed to the abstract {@link #handleLine} method.
   *

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 54

                  int pos = off;
    if (sawReturn && len > 0) {
      // Last call to add ended with a CR; we can handle the line now.
      if (finishLine(cbuf[pos] == '\n')) {
        pos++;
      }
    }

    int start = pos;

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 66

                        line.append(cbuf, start, pos - start);
          sawReturn = true;
          if (pos + 1 < end) {
            if (finishLine(cbuf[pos + 1] == '\n')) {
              pos++;
            }
          }
          start = pos + 1;
          break;

            

Reported by PMD.

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

Line: 36

              @ElementTypesAreNonnullByDefault
final class MultiInputStream extends InputStream {

  private Iterator<? extends ByteSource> it;
  @CheckForNull private InputStream in;

  /**
   * Creates a new instance.
   *

            

Reported by PMD.

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

Line: 36

              @ElementTypesAreNonnullByDefault
final class MultiInputStream extends InputStream {

  private Iterator<? extends ByteSource> it;
  @CheckForNull private InputStream in;

  /**
   * Creates a new instance.
   *

            

Reported by PMD.

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

Line: 37

              final class MultiInputStream extends InputStream {

  private Iterator<? extends ByteSource> it;
  @CheckForNull private InputStream in;

  /**
   * Creates a new instance.
   *
   * @param it an iterator of I/O suppliers that will provide each substream

            

Reported by PMD.

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

Line: 55

                    try {
        in.close();
      } finally {
        in = null;
      }
    }
  }

  /** Closes the current input stream and opens the next one, if any. */

            

Reported by PMD.

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

Line: 64

                private void advance() throws IOException {
    close();
    if (it.hasNext()) {
      in = it.next().openStream();
    }
  }

  @Override
  public int available() throws IOException {

            

Reported by PMD.

android/guava/src/com/google/common/io/MultiReader.java
5 issues
Overridable method 'close' called during object construction
Error

Line: 40

              
  MultiReader(Iterator<? extends CharSource> readers) throws IOException {
    this.it = readers;
    advance();
  }

  /** Closes the current reader and opens the next one, if any. */
  private void advance() throws IOException {
    close();

            

Reported by PMD.

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

Line: 35

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
class MultiReader extends Reader {
  private final Iterator<? extends CharSource> it;
  @CheckForNull private Reader current;

  MultiReader(Iterator<? extends CharSource> readers) throws IOException {
    this.it = readers;
    advance();

            

Reported by PMD.

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

Line: 36

              @ElementTypesAreNonnullByDefault
class MultiReader extends Reader {
  private final Iterator<? extends CharSource> it;
  @CheckForNull private Reader current;

  MultiReader(Iterator<? extends CharSource> readers) throws IOException {
    this.it = readers;
    advance();
  }

            

Reported by PMD.

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

Line: 47

                private void advance() throws IOException {
    close();
    if (it.hasNext()) {
      current = it.next().openStream();
    }
  }

  @Override
  public int read(char[] cbuf, int off, int len) throws IOException {

            

Reported by PMD.

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

Line: 91

                    try {
        current.close();
      } finally {
        current = null;
      }
    }
  }
}

            

Reported by PMD.

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

Line: 49

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class AbstractMapBasedMultiset<E extends @Nullable Object> extends AbstractMultiset<E>
    implements Serializable {

  transient ObjectCountHashMap<E> backingMap;
  transient long size;

  AbstractMapBasedMultiset(int distinctElements) {

            

Reported by PMD.

Field size has the same name as a method
Error

Line: 52

                  implements Serializable {

  transient ObjectCountHashMap<E> backingMap;
  transient long size;

  AbstractMapBasedMultiset(int distinctElements) {
    backingMap = newBackingMap(distinctElements);
  }


            

Reported by PMD.

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

Line: 167

                 * enough it's not especially worth it.
   */
  abstract class Itr<T extends @Nullable Object> implements Iterator<T> {
    int entryIndex = backingMap.firstIndex();
    int toRemove = -1;
    int expectedModCount = backingMap.modCount;

    @ParametricNullness
    abstract T result(int entryIndex);

            

Reported by PMD.

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

Line: 168

                 */
  abstract class Itr<T extends @Nullable Object> implements Iterator<T> {
    int entryIndex = backingMap.firstIndex();
    int toRemove = -1;
    int expectedModCount = backingMap.modCount;

    @ParametricNullness
    abstract T result(int entryIndex);


            

Reported by PMD.

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

Line: 169

                abstract class Itr<T extends @Nullable Object> implements Iterator<T> {
    int entryIndex = backingMap.firstIndex();
    int toRemove = -1;
    int expectedModCount = backingMap.modCount;

    @ParametricNullness
    abstract T result(int entryIndex);

    private void checkForConcurrentModification() {

            

Reported by PMD.

android/guava/src/com/google/common/collect/DiscreteDomain.java
5 issues
The String literal 'distance' appears 4 times in this file; the first occurrence is on line 82
Error

Line: 82

              
    @Override
    Integer offset(Integer origin, long distance) {
      checkNonnegative(distance, "distance");
      return Ints.checkedCast(origin.longValue() + distance);
    }

    @Override
    public long distance(Integer start, Integer end) {

            

Reported by PMD.

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

Line: 225

              
    @Override
    public long distance(BigInteger start, BigInteger end) {
      return end.subtract(start).max(MIN_LONG).min(MAX_LONG).longValue();
    }

    private Object readResolve() {
      return INSTANCE;
    }

            

Reported by PMD.

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

Line: 225

              
    @Override
    public long distance(BigInteger start, BigInteger end) {
      return end.subtract(start).max(MIN_LONG).min(MAX_LONG).longValue();
    }

    private Object readResolve() {
      return INSTANCE;
    }

            

Reported by PMD.

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

Line: 225

              
    @Override
    public long distance(BigInteger start, BigInteger end) {
      return end.subtract(start).max(MIN_LONG).min(MAX_LONG).longValue();
    }

    private Object readResolve() {
      return INSTANCE;
    }

            

Reported by PMD.

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

Line: 240

                  private static final long serialVersionUID = 0;
  }

  final boolean supportsFastOffset;

  /** Constructor for use by subclasses. */
  protected DiscreteDomain() {
    this(false);
  }

            

Reported by PMD.

android/guava/src/com/google/common/collect/EmptyContiguousSet.java
5 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 31

              @GwtCompatible(emulated = true)
@SuppressWarnings("rawtypes") // allow ungenerified Comparable types
@ElementTypesAreNonnullByDefault
final class EmptyContiguousSet<C extends Comparable> extends ContiguousSet<C> {
  EmptyContiguousSet(DiscreteDomain<C> domain) {
    super(domain);
  }

  @Override

            

Reported by PMD.

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

Line: 31

              @GwtCompatible(emulated = true)
@SuppressWarnings("rawtypes") // allow ungenerified Comparable types
@ElementTypesAreNonnullByDefault
final class EmptyContiguousSet<C extends Comparable> extends ContiguousSet<C> {
  EmptyContiguousSet(DiscreteDomain<C> domain) {
    super(domain);
  }

  @Override

            

Reported by PMD.

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

Line: 128

                public boolean equals(@CheckForNull Object object) {
    if (object instanceof Set) {
      Set<?> that = (Set<?>) object;
      return that.isEmpty();
    }
    return false;
  }

  @GwtIncompatible // not used in GWT

            

Reported by PMD.

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

Line: 146

              
  @GwtIncompatible // serialization
  private static final class SerializedForm<C extends Comparable> implements Serializable {
    private final DiscreteDomain<C> domain;

    private SerializedForm(DiscreteDomain<C> domain) {
      this.domain = domain;
    }


            

Reported by PMD.

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

Line: 168

                @GwtIncompatible // NavigableSet
  @Override
  ImmutableSortedSet<C> createDescendingSet() {
    return ImmutableSortedSet.emptySet(Ordering.natural().reverse());
  }
}

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/ForwardingObjectTester.java
5 issues
Avoid throwing raw exception types.
Design

Line: 44

                    DELEGATE_METHOD = ForwardingObject.class.getDeclaredMethod("delegate");
      DELEGATE_METHOD.setAccessible(true);
    } catch (SecurityException e) {
      throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
      throw new AssertionError(e);
    }
  }


            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 69

                                T stubber = doReturn(delegate).when(mock);
                  DELEGATE_METHOD.invoke(stubber);
                } catch (Exception e) {
                  throw new RuntimeException(e);
                }
                return mock;
              }
            });
  }

            

Reported by PMD.

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 Ben Yu
 */
final class ForwardingObjectTester {

  private static final Method DELEGATE_METHOD;

  static {
    try {

            

Reported by PMD.

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

Line: 66

                            public T apply(Object delegate) {
                T mock = mock(forwarderClass, CALLS_REAL_METHODS.get());
                try {
                  T stubber = doReturn(delegate).when(mock);
                  DELEGATE_METHOD.invoke(stubber);
                } catch (Exception e) {
                  throw new RuntimeException(e);
                }
                return mock;

            

Reported by PMD.

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

Line: 68

                              try {
                  T stubber = doReturn(delegate).when(mock);
                  DELEGATE_METHOD.invoke(stubber);
                } catch (Exception e) {
                  throw new RuntimeException(e);
                }
                return mock;
              }
            });

            

Reported by PMD.

guava-tests/test/com/google/common/math/MathBenchmarking.java
5 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: 31

               *
 * @author Louis Wasserman
 */
final class MathBenchmarking {
  static final int ARRAY_SIZE = 0x10000;
  static final int ARRAY_MASK = 0x0ffff;
  static final Random RANDOM_SOURCE = new Random(314159265358979L);
  static final int MAX_EXPONENT = 100;


            

Reported by PMD.

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

Line: 86

                  BigInteger result;
    do {
      result = randomNonNegativeBigInteger(numBits);
    } while (result.signum() == 0);
    return result;
  }

  /**
   * Generates a number in [0, 2^numBits) with an exponential distribution. The floor of the log2 of

            

Reported by PMD.

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

Line: 110

                 */
  static BigInteger randomNonZeroBigInteger(int numBits) {
    BigInteger result = randomPositiveBigInteger(numBits);
    return RANDOM_SOURCE.nextBoolean() ? result : result.negate();
  }

  /**
   * Chooses a number in (-2^numBits, 2^numBits) at random, with density concentrated in numbers of
   * lower magnitude.

            

Reported by PMD.

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

Line: 122

                    if (RANDOM_SOURCE.nextBoolean()) {
        return randomNonNegativeBigInteger(numBits);
      }
      BigInteger neg = randomNonNegativeBigInteger(numBits).negate();
      if (neg.signum() != 0) {
        return neg;
      }
    }
  }

            

Reported by PMD.

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

Line: 123

                      return randomNonNegativeBigInteger(numBits);
      }
      BigInteger neg = randomNonNegativeBigInteger(numBits).negate();
      if (neg.signum() != 0) {
        return neg;
      }
    }
  }


            

Reported by PMD.