The following issues were found

guava/src/com/google/common/io/ByteSource.java
69 issues
Avoid reassigning parameters such as 'length'
Design

Line: 641

                  }

    @Override
    public ByteSource slice(long offset, long length) {
      checkArgument(offset >= 0, "offset (%s) may not be negative", offset);
      checkArgument(length >= 0, "length (%s) may not be negative", length);

      offset = Math.min(offset, this.length);
      length = Math.min(length, this.length - offset);

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 641

                  }

    @Override
    public ByteSource slice(long offset, long length) {
      checkArgument(offset >= 0, "offset (%s) may not be negative", offset);
      checkArgument(length >= 0, "length (%s) may not be negative", length);

      offset = Math.min(offset, this.length);
      length = Math.min(length, this.length - offset);

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 15

               * the License.
 */

package com.google.common.io;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.io.ByteStreams.createBuffer;
import static com.google.common.io.ByteStreams.skipUpTo;

            

Reported by PMD.

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

Line: 78

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class ByteSource {

  /** Constructor for use by subclasses. */
  protected ByteSource() {}

  /**

            

Reported by PMD.

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

Line: 153

                 */
  public boolean isEmpty() throws IOException {
    Optional<Long> sizeIfKnown = sizeIfKnown();
    if (sizeIfKnown.isPresent()) {
      return sizeIfKnown.get() == 0L;
    }
    Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openStream());

            

Reported by PMD.

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

Line: 158

                  }
    Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openStream());
      return in.read() == -1;
    } 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: 159

                  Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openStream());
      return in.read() == -1;
    } 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: 160

                  try {
      InputStream in = closer.register(openStream());
      return in.read() == -1;
    } 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: 207

                 */
  public long size() throws IOException {
    Optional<Long> sizeIfKnown = sizeIfKnown();
    if (sizeIfKnown.isPresent()) {
      return sizeIfKnown.get();
    }

    Closer closer = Closer.create();
    try {

            

Reported by PMD.

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

Line: 213

              
    Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openStream());
      return countBySkipping(in);
    } catch (IOException e) {
      // skip may not be supported... at any rate, try reading
    } finally {
      closer.close();

            

Reported by PMD.

guava-testlib/src/com/google/common/testing/FreshValueGenerator.java
69 issues
Avoid throwing raw exception types.
Design

Line: 278

                    return generator.invoke(this, args);
    } catch (InvocationTargetException e) {
      throwIfUnchecked(e.getCause());
      throw new RuntimeException(e.getCause());
    } catch (Exception e) {
      throwIfUnchecked(e);
      throw new RuntimeException(e);
    }
  }

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 281

                    throw new RuntimeException(e.getCause());
    } catch (Exception e) {
      throwIfUnchecked(e);
      throw new RuntimeException(e);
    }
  }

  private final class FreshInvocationHandler extends AbstractInvocationHandler {
    private final int identity = generateInt();

            

Reported by PMD.

Do not use the short type
Performance

Line: 417

                }

  @Generates
  short generateShort() {
    return (short) generateInt();
  }

  @Generates
  Short generateShortObject() {

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 383

              
  @Generates
  Integer generateInteger() {
    return new Integer(generateInt());
  }

  @Generates
  long generateLong() {
    return generateInt();

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 393

              
  @Generates
  Long generateLongObject() {
    return new Long(generateLong());
  }

  @Generates
  float generateFloat() {
    return generateInt();

            

Reported by PMD.

Avoid instantiating Short objects. Call Short.valueOf() instead
Performance

Line: 423

              
  @Generates
  Short generateShortObject() {
    return new Short(generateShort());
  }

  @Generates
  byte generateByte() {
    return (byte) generateInt();

            

Reported by PMD.

Avoid instantiating Byte objects. Call Byte.valueOf() instead
Performance

Line: 433

              
  @Generates
  Byte generateByteObject() {
    return new Byte(generateByte());
  }

  @Generates
  char generateChar() {
    return generateString().charAt(0);

            

Reported by PMD.

Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead.
Performance

Line: 453

              
  @Generates
  Boolean generateBooleanObject() {
    return new Boolean(generateBoolean());
  }

  @Generates
  UnsignedInteger generateUnsignedInteger() {
    return UnsignedInteger.fromIntBits(generateInt());

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.annotations.GwtIncompatible;

            

Reported by PMD.

High amount of different objects as members denotes a high coupling
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.annotations.GwtIncompatible;

            

Reported by PMD.

guava-tests/test/com/google/common/io/CharStreamsTest.java
69 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               *
 * @author Chris Nokleberg
 */
public class CharStreamsTest extends IoTestCase {

  private static final String TEXT = "The quick brown fox jumped over the lazy dog.";

  public void testToString() throws IOException {
    assertEquals(TEXT, CharStreams.toString(new StringReader(TEXT)));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 40

              
  private static final String TEXT = "The quick brown fox jumped over the lazy dog.";

  public void testToString() throws IOException {
    assertEquals(TEXT, CharStreams.toString(new StringReader(TEXT)));
  }

  public void testReadLines() throws IOException {
    List<String> lines = CharStreams.readLines(new StringReader("a\nb\nc"));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 44

                  assertEquals(TEXT, CharStreams.toString(new StringReader(TEXT)));
  }

  public void testReadLines() throws IOException {
    List<String> lines = CharStreams.readLines(new StringReader("a\nb\nc"));
    assertEquals(ImmutableList.of("a", "b", "c"), lines);
  }

  public void testReadLines_withLineProcessor() throws IOException {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 49

                  assertEquals(ImmutableList.of("a", "b", "c"), lines);
  }

  public void testReadLines_withLineProcessor() throws IOException {
    String text = "a\nb\nc";

    // Test a LineProcessor that always returns false.
    Reader r = new StringReader(text);
    LineProcessor<Integer> alwaysFalse =

            

Reported by PMD.

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

Line: 49

                  assertEquals(ImmutableList.of("a", "b", "c"), lines);
  }

  public void testReadLines_withLineProcessor() throws IOException {
    String text = "a\nb\nc";

    // Test a LineProcessor that always returns false.
    Reader r = new StringReader(text);
    LineProcessor<Integer> alwaysFalse =

            

Reported by PMD.

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

Line: 53

                  String text = "a\nb\nc";

    // Test a LineProcessor that always returns false.
    Reader r = new StringReader(text);
    LineProcessor<Integer> alwaysFalse =
        new LineProcessor<Integer>() {
          int seen;

          @Override

            

Reported by PMD.

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

Line: 72

                  assertEquals(
        "processLine was called more than once",
        1,
        CharStreams.readLines(r, alwaysFalse).intValue());

    // Test a LineProcessor that always returns true.
    r = new StringReader(text);
    LineProcessor<Integer> alwaysTrue =
        new LineProcessor<Integer>() {

            

Reported by PMD.

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

Line: 94

                  assertEquals(
        "processLine was not called for all the lines",
        3,
        CharStreams.readLines(r, alwaysTrue).intValue());

    // Test a LineProcessor that is conditional.
    r = new StringReader(text);
    final StringBuilder sb = new StringBuilder();
    LineProcessor<Integer> conditional =

            

Reported by PMD.

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

Line: 115

                          return seen;
          }
        };
    assertEquals(2, CharStreams.readLines(r, conditional).intValue());
    assertEquals("ab", sb.toString());
  }

  public void testSkipFully_EOF() throws IOException {
    Reader reader = new StringReader("abcde");

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 119

                  assertEquals("ab", sb.toString());
  }

  public void testSkipFully_EOF() throws IOException {
    Reader reader = new StringReader("abcde");
    try {
      CharStreams.skipFully(reader, 6);
      fail("expected EOFException");
    } catch (EOFException expected) {

            

Reported by PMD.

guava-tests/test/com/google/common/cache/LocalCacheMapComputeTest.java
69 issues
Avoid throwing raw exception types.
Design

Line: 192

                              .compute(
                    key,
                    (k, v) -> {
                      throw new RuntimeException();
                    });
          });
      fail("Should not get here");
    } catch (RuntimeException ex) {
    }

            

Reported by PMD.

This final field could be made static
Design

Line: 34

              
/** Test Java8 map.compute in concurrent cache context. */
public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper

            

Reported by PMD.

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

Line: 34

              
/** Test Java8 map.compute in concurrent cache context. */
public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper

            

Reported by PMD.

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

Line: 35

              /** Test Java8 map.compute in concurrent cache context. */
public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {

            

Reported by PMD.

This final field could be made static
Design

Line: 35

              /** Test Java8 map.compute in concurrent cache context. */
public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {

            

Reported by PMD.

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

Line: 36

              public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {
    IntStream.range(0, count).parallel().forEach(consumer);

            

Reported by PMD.

This final field could be made static
Design

Line: 36

              public class LocalCacheMapComputeTest extends TestCase {
  final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {
    IntStream.range(0, count).parallel().forEach(consumer);

            

Reported by PMD.

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

Line: 37

                final int count = 10000;
  final String delimiter = "-";
  final String key = "key";
  Cache<String, String> cache;

  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {
    IntStream.range(0, count).parallel().forEach(consumer);
  }

            

Reported by PMD.

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

Line: 41

              
  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {
    IntStream.range(0, count).parallel().forEach(consumer);
  }

  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 41

              
  // helper
  private static void doParallelCacheOp(int count, IntConsumer consumer) {
    IntStream.range(0, count).parallel().forEach(consumer);
  }

  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

guava-tests/test/com/google/common/cache/CacheTesting.java
68 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.cache;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;

            

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

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

Possible God Class (WMC=79, ATFD=65, TCC=0.000%)
Design

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 72

                    Preconditions.checkState(valueRef instanceof Reference);
      Reference<V> ref = (Reference<V>) valueRef;
      if (ref != null) {
        ref.clear();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 97

                  checkNotNull(cache);
    checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    return map.getEntry(key);
  }

  /**
   * Forces the segment containing the given {@code key} to expand (see {@link Segment#expand()}.
   */

            

Reported by PMD.

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

Line: 107

                  checkNotNull(cache);
    checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    int hash = map.hash(key);
    Segment<K, V> segment = map.segmentFor(hash);
    segment.expand();
  }

  /**

            

Reported by PMD.

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

Line: 108

                  checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    int hash = map.hash(key);
    Segment<K, V> segment = map.segmentFor(hash);
    segment.expand();
  }

  /**
   * Gets the {@link LocalCache} used by the given {@link Cache}, if any, or throws an

            

Reported by PMD.

android/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java
68 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               * @author mike nonemacher
 */

public class GcFinalizationTest extends TestCase {

  // ----------------------------------------------------------------
  // Ordinary tests of successful method execution
  // ----------------------------------------------------------------


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 42

                // Ordinary tests of successful method execution
  // ----------------------------------------------------------------

  public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

Avoid unused local variables such as 'x'.
Design

Line: 44

              
  public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }

            

Reported by PMD.

The initializer for variable 'x' is never used (overwritten on line 51)
Design

Line: 45

                public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }
        };

            

Reported by PMD.

Last statement in finalize method should be a call to super.finalize()
Error

Line: 48

                      new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());

            

Reported by PMD.

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

Line: 51

                          latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {

            

Reported by PMD.

The value assigned to variable 'x' is never used
Design

Line: 51

                          latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 53

                      };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 56

                  assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

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

Line: 56

                  assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

guava/src/com/google/common/collect/ImmutableRangeSet.java
68 issues
Possible God Class (WMC=72, ATFD=34, TCC=18.347%)
Design

Line: 52

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableRangeSet<C extends Comparable> extends AbstractRangeSet<C>
    implements Serializable {

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


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 52

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableRangeSet<C extends Comparable> extends AbstractRangeSet<C>
    implements Serializable {

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


            

Reported by PMD.

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

Line: 52

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableRangeSet<C extends Comparable> extends AbstractRangeSet<C>
    implements Serializable {

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


            

Reported by PMD.

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

Line: 52

              @Beta
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableRangeSet<C extends Comparable> extends AbstractRangeSet<C>
    implements Serializable {

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


            

Reported by PMD.

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

Line: 53

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableRangeSet<C extends Comparable> extends AbstractRangeSet<C>
    implements Serializable {

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

  private static final ImmutableRangeSet<Comparable<?>> ALL =

            

Reported by PMD.

Field ALL has the same name as a method
Error

Line: 58

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

  private static final ImmutableRangeSet<Comparable<?>> ALL =
      new ImmutableRangeSet<>(ImmutableList.of(Range.<Comparable<?>>all()));

  /**
   * Returns a {@code Collector} that accumulates the input elements into a new {@code
   * ImmutableRangeSet}. As in {@link Builder}, overlapping ranges are not permitted and adjacent

            

Reported by PMD.

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

Line: 78

                 *
   * <p><b>Performance note:</b> the instance returned is a singleton.
   */
  @SuppressWarnings("unchecked")
  public static <C extends Comparable> ImmutableRangeSet<C> of() {
    return (ImmutableRangeSet<C>) EMPTY;
  }

  /**

            

Reported by PMD.

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

Line: 115

              
    if (rangeSet instanceof ImmutableRangeSet) {
      ImmutableRangeSet<C> immutableRangeSet = (ImmutableRangeSet<C>) rangeSet;
      if (!immutableRangeSet.isPartialView()) {
        return immutableRangeSet;
      }
    }
    return new ImmutableRangeSet<C>(ImmutableList.copyOf(rangeSet.asRanges()));
  }

            

Reported by PMD.

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

Line: 168

                          ANY_PRESENT,
            NEXT_HIGHER);
    if (ceilingIndex < ranges.size()
        && ranges.get(ceilingIndex).isConnected(otherRange)
        && !ranges.get(ceilingIndex).intersection(otherRange).isEmpty()) {
      return true;
    }
    return ceilingIndex > 0
        && ranges.get(ceilingIndex - 1).isConnected(otherRange)

            

Reported by PMD.

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

Line: 169

                          NEXT_HIGHER);
    if (ceilingIndex < ranges.size()
        && ranges.get(ceilingIndex).isConnected(otherRange)
        && !ranges.get(ceilingIndex).intersection(otherRange).isEmpty()) {
      return true;
    }
    return ceilingIndex > 0
        && ranges.get(ceilingIndex - 1).isConnected(otherRange)
        && !ranges.get(ceilingIndex - 1).intersection(otherRange).isEmpty();

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/ForwardingMapTest.java
68 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static java.lang.reflect.Modifier.STATIC;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;

            

Reported by PMD.

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

Line: 58

               * @author Louis Wasserman
 */
public class ForwardingMapTest extends TestCase {
  static class StandardImplForwardingMap<K, V> extends ForwardingMap<K, V> {
    private final Map<K, V> backingMap;

    StandardImplForwardingMap(Map<K, V> backingMap) {
      this.backingMap = backingMap;
    }

            

Reported by PMD.

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

Line: 59

               */
public class ForwardingMapTest extends TestCase {
  static class StandardImplForwardingMap<K, V> extends ForwardingMap<K, V> {
    private final Map<K, V> backingMap;

    StandardImplForwardingMap(Map<K, V> backingMap) {
      this.backingMap = backingMap;
    }


            

Reported by PMD.

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

Line: 120

                    return new StandardEntrySet() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
          return delegate().entrySet().iterator();
        }
      };
    }

    @Override

            

Reported by PMD.

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

Line: 120

                    return new StandardEntrySet() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
          return delegate().entrySet().iterator();
        }
      };
    }

    @Override

            

Reported by PMD.

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

Line: 136

                  }
  }

  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTestSuite(ForwardingMapTest.class);
    suite.addTest(
        MapTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 187

                  return suite;
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Map.class,
            new Function<Map, Map>() {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 187

                  return suite;
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Map.class,
            new Function<Map, Map>() {

            

Reported by PMD.

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

Line: 188

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Map.class,
            new Function<Map, Map>() {
              @Override

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 200

                          });
  }

  public void testEquals() {
    Map<Integer, String> map1 = ImmutableMap.of(1, "one");
    Map<Integer, String> map2 = ImmutableMap.of(2, "two");
    new EqualsTester()
        .addEqualityGroup(map1, wrap(map1), wrap(map1))
        .addEqualityGroup(map2, wrap(map2))

            

Reported by PMD.

guava-testlib/test/com/google/common/testing/GcFinalizationTest.java
68 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               * @author mike nonemacher
 */

public class GcFinalizationTest extends TestCase {

  // ----------------------------------------------------------------
  // Ordinary tests of successful method execution
  // ----------------------------------------------------------------


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 42

                // Ordinary tests of successful method execution
  // ----------------------------------------------------------------

  public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

Avoid unused local variables such as 'x'.
Design

Line: 44

              
  public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }

            

Reported by PMD.

The initializer for variable 'x' is never used (overwritten on line 51)
Design

Line: 45

                public void testAwait_CountDownLatch() {
    final CountDownLatch latch = new CountDownLatch(1);
    Object x =
        new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }
        };

            

Reported by PMD.

Last statement in finalize method should be a call to super.finalize()
Error

Line: 48

                      new Object() {
          @Override
          protected void finalize() {
            latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());

            

Reported by PMD.

The value assigned to variable 'x' is never used
Design

Line: 51

                          latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {

            

Reported by PMD.

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

Line: 51

                          latch.countDown();
          }
        };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 53

                      };
    x = null; // Hint to the JIT that x is unreachable
    GcFinalization.await(latch);
    assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 56

                  assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

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

Line: 56

                  assertEquals(0, latch.getCount());
  }

  public void testAwaitDone_Future() {
    final SettableFuture<Void> future = SettableFuture.create();
    Object x =
        new Object() {
          @Override
          protected void finalize() {

            

Reported by PMD.

android/guava-tests/test/com/google/common/cache/CacheTesting.java
68 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.cache;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;

            

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

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

Possible God Class (WMC=79, ATFD=65, TCC=0.000%)
Design

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 55

               * @author mike nonemacher
 */
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
class CacheTesting {

  /**
   * Poke into the Cache internals to simulate garbage collection of the value associated with the
   * given key. This assumes that the associated entry is a WeakValueReference or a
   * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if

            

Reported by PMD.

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

Line: 72

                    Preconditions.checkState(valueRef instanceof Reference);
      Reference<V> ref = (Reference<V>) valueRef;
      if (ref != null) {
        ref.clear();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 97

                  checkNotNull(cache);
    checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    return map.getEntry(key);
  }

  /**
   * Forces the segment containing the given {@code key} to expand (see {@link Segment#expand()}.
   */

            

Reported by PMD.

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

Line: 107

                  checkNotNull(cache);
    checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    int hash = map.hash(key);
    Segment<K, V> segment = map.segmentFor(hash);
    segment.expand();
  }

  /**

            

Reported by PMD.

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

Line: 108

                  checkNotNull(key);
    LocalCache<K, V> map = toLocalCache(cache);
    int hash = map.hash(key);
    Segment<K, V> segment = map.segmentFor(hash);
    segment.expand();
  }

  /**
   * Gets the {@link LocalCache} used by the given {@link Cache}, if any, or throws an

            

Reported by PMD.