The following issues were found

guava-testlib/test/com/google/common/util/concurrent/testing/TestingExecutorsTest.java
46 issues
Avoid throwing raw exception types.
Design

Line: 108

                      new Runnable() {
          @Override
          public void run() {
            throw new RuntimeException("Oh no!");
          }
        };

    Future<?> future = TestingExecutors.sameThreadScheduledExecutor().submit(runnable);
    try {

            

Reported by PMD.

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

Line: 36

               * @author Eric Chang
 */
public class TestingExecutorsTest extends TestCase {
  private volatile boolean taskDone;

  public void testNoOpScheduledExecutor() throws InterruptedException {
    taskDone = false;
    Runnable task =
        new Runnable() {

            

Reported by PMD.

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

Line: 38

              public class TestingExecutorsTest extends TestCase {
  private volatile boolean taskDone;

  public void testNoOpScheduledExecutor() throws InterruptedException {
    taskDone = false;
    Runnable task =
        new Runnable() {
          @Override
          public void run() {

            

Reported by PMD.

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

Line: 38

              public class TestingExecutorsTest extends TestCase {
  private volatile boolean taskDone;

  public void testNoOpScheduledExecutor() throws InterruptedException {
    taskDone = false;
    Runnable task =
        new Runnable() {
          @Override
          public void run() {

            

Reported by PMD.

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

Line: 48

                        }
        };
    ScheduledFuture<?> future =
        TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
    Thread.sleep(20);
    assertFalse(taskDone);
    assertFalse(future.isDone());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                  ScheduledFuture<?> future =
        TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
    Thread.sleep(20);
    assertFalse(taskDone);
    assertFalse(future.isDone());
  }

  public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                      TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
    Thread.sleep(20);
    assertFalse(taskDone);
    assertFalse(future.isDone());
  }

  public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    assertFalse(executor.isShutdown());

            

Reported by PMD.

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

Line: 51

                      TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
    Thread.sleep(20);
    assertFalse(taskDone);
    assertFalse(future.isDone());
  }

  public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    assertFalse(executor.isShutdown());

            

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

                  assertFalse(future.isDone());
  }

  public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    assertFalse(executor.isShutdown());
    assertFalse(executor.isTerminated());
    executor.shutdown();
    assertTrue(executor.isShutdown());

            

Reported by PMD.

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

Line: 54

                  assertFalse(future.isDone());
  }

  public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    assertFalse(executor.isShutdown());
    assertFalse(executor.isTerminated());
    executor.shutdown();
    assertTrue(executor.isShutdown());

            

Reported by PMD.

guava-testlib/test/com/google/common/testing/anotherpackage/ForwardingWrapperTesterTest.java
46 issues
This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing.anotherpackage;

import static com.google.common.truth.Truth.assertThat;

import com.google.common.base.Equivalence;
import com.google.common.base.Function;

            

Reported by PMD.

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

Line: 44

               *
 * @author Ben Yu
 */
public class ForwardingWrapperTesterTest extends TestCase {

  private final ForwardingWrapperTester tester = new ForwardingWrapperTester();

  public void testGoodForwarder() {
    tester.testForwarding(

            

Reported by PMD.

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

Line: 46

               */
public class ForwardingWrapperTesterTest extends TestCase {

  private final ForwardingWrapperTester tester = new ForwardingWrapperTester();

  public void testGoodForwarder() {
    tester.testForwarding(
        Arithmetic.class,
        new Function<Arithmetic, Arithmetic>() {

            

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

              
  private final ForwardingWrapperTester tester = new ForwardingWrapperTester();

  public void testGoodForwarder() {
    tester.testForwarding(
        Arithmetic.class,
        new Function<Arithmetic, Arithmetic>() {
          @Override
          public Arithmetic apply(Arithmetic arithmetic) {

            

Reported by PMD.

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

Line: 48

              
  private final ForwardingWrapperTester tester = new ForwardingWrapperTester();

  public void testGoodForwarder() {
    tester.testForwarding(
        Arithmetic.class,
        new Function<Arithmetic, Arithmetic>() {
          @Override
          public Arithmetic apply(Arithmetic arithmetic) {

            

Reported by PMD.

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

Line: 67

                      });
  }

  public void testVoidMethodForwarding() {
    tester.testForwarding(
        Runnable.class,
        new Function<Runnable, Runnable>() {
          @Override
          public Runnable apply(final Runnable runnable) {

            

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

                      });
  }

  public void testVoidMethodForwarding() {
    tester.testForwarding(
        Runnable.class,
        new Function<Runnable, Runnable>() {
          @Override
          public Runnable apply(final Runnable runnable) {

            

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

                      });
  }

  public void testToStringForwarding() {
    tester.testForwarding(
        Runnable.class,
        new Function<Runnable, Runnable>() {
          @Override
          public Runnable apply(final Runnable runnable) {

            

Reported by PMD.

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

Line: 78

                      });
  }

  public void testToStringForwarding() {
    tester.testForwarding(
        Runnable.class,
        new Function<Runnable, Runnable>() {
          @Override
          public Runnable apply(final Runnable runnable) {

            

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

                      });
  }

  public void testFailsToForwardToString() {
    assertFailure(
        Runnable.class,
        new Function<Runnable, Runnable>() {
          @Override
          public Runnable apply(final Runnable runnable) {

            

Reported by PMD.

guava/src/com/google/common/primitives/Shorts.java
46 issues
Do not use the short type
Performance

Line: 63

                 *
   * @since 10.0
   */
  public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);

  /**
   * Returns a hash code for {@code value}; equal to the result of invoking {@code ((Short)
   * value).hashCode()}.
   *

            

Reported by PMD.

Do not use the short type
Performance

Line: 74

                 * @param value a primitive {@code short} value
   * @return a hash code for the value
   */
  public static int hashCode(short value) {
    return value;
  }

  /**
   * Returns the {@code short} value that is equal to {@code value}, if possible.

            

Reported by PMD.

Do not use the short type
Performance

Line: 86

                 * @throws IllegalArgumentException if {@code value} is greater than {@link Short#MAX_VALUE} or
   *     less than {@link Short#MIN_VALUE}
   */
  public static short checkedCast(long value) {
    short result = (short) value;
    checkArgument(result == value, "Out of range: %s", value);
    return result;
  }


            

Reported by PMD.

Do not use the short type
Performance

Line: 87

                 *     less than {@link Short#MIN_VALUE}
   */
  public static short checkedCast(long value) {
    short result = (short) value;
    checkArgument(result == value, "Out of range: %s", value);
    return result;
  }

  /**

            

Reported by PMD.

Do not use the short type
Performance

Line: 99

                 * @return the same value cast to {@code short} if it is in the range of the {@code short} type,
   *     {@link Short#MAX_VALUE} if it is too large, or {@link Short#MIN_VALUE} if it is too small
   */
  public static short saturatedCast(long value) {
    if (value > Short.MAX_VALUE) {
      return Short.MAX_VALUE;
    }
    if (value < Short.MIN_VALUE) {
      return Short.MIN_VALUE;

            

Reported by PMD.

Do not use the short type
Performance

Line: 121

                 * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
   *     greater than {@code b}; or zero if they are equal
   */
  public static int compare(short a, short b) {
    return a - b; // safe due to restricted range
  }

  /**
   * Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.

            

Reported by PMD.

Do not use the short type
Performance

Line: 121

                 * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
   *     greater than {@code b}; or zero if they are equal
   */
  public static int compare(short a, short b) {
    return a - b; // safe due to restricted range
  }

  /**
   * Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.

            

Reported by PMD.

Do not use the short type
Performance

Line: 132

                 * @param target a primitive {@code short} value
   * @return {@code true} if {@code array[i] == target} for some value of {@code i}
   */
  public static boolean contains(short[] array, short target) {
    for (short value : array) {
      if (value == target) {
        return true;
      }
    }

            

Reported by PMD.

Do not use the short type
Performance

Line: 133

                 * @return {@code true} if {@code array[i] == target} for some value of {@code i}
   */
  public static boolean contains(short[] array, short target) {
    for (short value : array) {
      if (value == target) {
        return true;
      }
    }
    return false;

            

Reported by PMD.

Do not use the short type
Performance

Line: 149

                 * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
   *     such index exists.
   */
  public static int indexOf(short[] array, short target) {
    return indexOf(array, target, 0, array.length);
  }

  // TODO(kevinb): consider making this public
  private static int indexOf(short[] array, short target, int start, int end) {

            

Reported by PMD.

guava-tests/test/com/google/common/escape/EscapersTest.java
46 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: 28

              /** @author David Beaumont */
@GwtCompatible
public class EscapersTest extends TestCase {
  public void testNullEscaper() throws IOException {
    Escaper escaper = Escapers.nullEscaper();
    EscaperAsserts.assertBasic(escaper);
    String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
    assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

            

Reported by PMD.

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

Line: 32

                  Escaper escaper = Escapers.nullEscaper();
    EscaperAsserts.assertBasic(escaper);
    String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
    assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();

            

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

                  assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }


            

Reported by PMD.

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

Line: 37

              
  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).

            

Reported by PMD.

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

Line: 37

              
  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

                public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();

            

Reported by PMD.

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

Line: 38

                public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();

            

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

                  assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }


            

Reported by PMD.

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

Line: 43

              
  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }

  public void testBuilderRetainsState() {
    // Setting a safe range and unsafe replacement works as expected.

            

Reported by PMD.

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

Line: 43

              
  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }

  public void testBuilderRetainsState() {
    // Setting a safe range and unsafe replacement works as expected.

            

Reported by PMD.

android/guava-tests/test/com/google/common/cache/NullCacheTest.java
46 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

               * @author mike nonemacher
 */
public class NullCacheTest extends TestCase {
  QueuingRemovalListener<Object, Object> listener;

  @Override
  protected void setUp() {
    listener = queuingRemovalListener();
  }

            

Reported by PMD.

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

Line: 37

              public class NullCacheTest extends TestCase {
  QueuingRemovalListener<Object, Object> listener;

  @Override
  protected void setUp() {
    listener = queuingRemovalListener();
  }

  public void testGet() {

            

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

                  listener = queuingRemovalListener();
  }

  public void testGet() {
    Object computed = new Object();
    LoadingCache<Object, Object> cache =
        CacheBuilder.newBuilder()
            .maximumSize(0)
            .removalListener(listener)

            

Reported by PMD.

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

Line: 42

                  listener = queuingRemovalListener();
  }

  public void testGet() {
    Object computed = new Object();
    LoadingCache<Object, Object> cache =
        CacheBuilder.newBuilder()
            .maximumSize(0)
            .removalListener(listener)

            

Reported by PMD.

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

Line: 51

                          .build(constantLoader(computed));

    Object key = new Object();
    assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                          .build(constantLoader(computed));

    Object key = new Object();
    assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());

            

Reported by PMD.

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

Line: 53

                  Object key = new Object();
    assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());
    checkEmpty(cache);
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 53

                  Object key = new Object();
    assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());
    checkEmpty(cache);
  }

            

Reported by PMD.

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

Line: 54

                  assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());
    checkEmpty(cache);
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 54

                  assertSame(computed, cache.getUnchecked(key));
    RemovalNotification<Object, Object> notification = listener.remove();
    assertSame(key, notification.getKey());
    assertSame(computed, notification.getValue());
    assertSame(RemovalCause.SIZE, notification.getCause());
    assertTrue(listener.isEmpty());
    checkEmpty(cache);
  }


            

Reported by PMD.

guava-tests/test/com/google/common/graph/GraphMutationTest.java
46 issues
JUnit tests should include assert() or fail()
Design

Line: 40

                private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES

  @Test
  public void directedGraph() {
    testGraphMutation(GraphBuilder.directed());
  }

  @Test
  public void undirectedGraph() {

            

Reported by PMD.

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

Line: 45

                }

  @Test
  public void undirectedGraph() {
    testGraphMutation(GraphBuilder.undirected());
  }

  private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

            

Reported by PMD.

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

Line: 49

                  testGraphMutation(GraphBuilder.undirected());
  }

  private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();


            

Reported by PMD.

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

Line: 53

                  Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);


            

Reported by PMD.

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

Line: 55

                  for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 55

                  for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 56

                    MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 56

                    MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 59

                    assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
      while (graph.edges().size() < NUM_EDGES) {
        graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));

            

Reported by PMD.

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

Line: 59

                    assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
      while (graph.edges().size() < NUM_EDGES) {
        graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/GraphMutationTest.java
46 issues
JUnit tests should include assert() or fail()
Design

Line: 40

                private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES

  @Test
  public void directedGraph() {
    testGraphMutation(GraphBuilder.directed());
  }

  @Test
  public void undirectedGraph() {

            

Reported by PMD.

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

Line: 45

                }

  @Test
  public void undirectedGraph() {
    testGraphMutation(GraphBuilder.undirected());
  }

  private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

            

Reported by PMD.

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

Line: 49

                  testGraphMutation(GraphBuilder.undirected());
  }

  private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();


            

Reported by PMD.

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

Line: 53

                  Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);


            

Reported by PMD.

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

Line: 55

                  for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 55

                  for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 56

                    MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 56

                    MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();

      assertThat(graph.nodes()).isEmpty();
      assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 59

                    assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
      while (graph.edges().size() < NUM_EDGES) {
        graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));

            

Reported by PMD.

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

Line: 59

                    assertThat(graph.edges()).isEmpty();
      AbstractGraphTest.validateGraph(graph);

      while (graph.nodes().size() < NUM_NODES) {
        graph.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
      while (graph.edges().size() < NUM_EDGES) {
        graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));

            

Reported by PMD.

android/guava-tests/test/com/google/common/escape/EscapersTest.java
46 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: 28

              /** @author David Beaumont */
@GwtCompatible
public class EscapersTest extends TestCase {
  public void testNullEscaper() throws IOException {
    Escaper escaper = Escapers.nullEscaper();
    EscaperAsserts.assertBasic(escaper);
    String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
    assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

            

Reported by PMD.

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

Line: 32

                  Escaper escaper = Escapers.nullEscaper();
    EscaperAsserts.assertBasic(escaper);
    String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
    assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();

            

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

                  assertEquals("null escaper should have no effect", s, escaper.escape(s));
  }

  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }


            

Reported by PMD.

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

Line: 37

              
  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).

            

Reported by PMD.

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

Line: 37

              
  public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

                public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();

            

Reported by PMD.

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

Line: 38

                public void testBuilderInitialStateNoReplacement() {
    // Unsafe characters aren't modified by default (unsafeReplacement == null).
    Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
    assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();

            

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

                  assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
  }

  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }


            

Reported by PMD.

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

Line: 43

              
  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }

  public void testBuilderRetainsState() {
    // Setting a safe range and unsafe replacement works as expected.

            

Reported by PMD.

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

Line: 43

              
  public void testBuilderInitialStateNoneUnsafe() {
    // No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
    Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
    assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
  }

  public void testBuilderRetainsState() {
    // Setting a safe range and unsafe replacement works as expected.

            

Reported by PMD.

android/guava/src/com/google/common/primitives/Shorts.java
46 issues
Do not use the short type
Performance

Line: 63

                 *
   * @since 10.0
   */
  public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);

  /**
   * Returns a hash code for {@code value}; equal to the result of invoking {@code ((Short)
   * value).hashCode()}.
   *

            

Reported by PMD.

Do not use the short type
Performance

Line: 74

                 * @param value a primitive {@code short} value
   * @return a hash code for the value
   */
  public static int hashCode(short value) {
    return value;
  }

  /**
   * Returns the {@code short} value that is equal to {@code value}, if possible.

            

Reported by PMD.

Do not use the short type
Performance

Line: 86

                 * @throws IllegalArgumentException if {@code value} is greater than {@link Short#MAX_VALUE} or
   *     less than {@link Short#MIN_VALUE}
   */
  public static short checkedCast(long value) {
    short result = (short) value;
    checkArgument(result == value, "Out of range: %s", value);
    return result;
  }


            

Reported by PMD.

Do not use the short type
Performance

Line: 87

                 *     less than {@link Short#MIN_VALUE}
   */
  public static short checkedCast(long value) {
    short result = (short) value;
    checkArgument(result == value, "Out of range: %s", value);
    return result;
  }

  /**

            

Reported by PMD.

Do not use the short type
Performance

Line: 99

                 * @return the same value cast to {@code short} if it is in the range of the {@code short} type,
   *     {@link Short#MAX_VALUE} if it is too large, or {@link Short#MIN_VALUE} if it is too small
   */
  public static short saturatedCast(long value) {
    if (value > Short.MAX_VALUE) {
      return Short.MAX_VALUE;
    }
    if (value < Short.MIN_VALUE) {
      return Short.MIN_VALUE;

            

Reported by PMD.

Do not use the short type
Performance

Line: 121

                 * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
   *     greater than {@code b}; or zero if they are equal
   */
  public static int compare(short a, short b) {
    return a - b; // safe due to restricted range
  }

  /**
   * Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.

            

Reported by PMD.

Do not use the short type
Performance

Line: 121

                 * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
   *     greater than {@code b}; or zero if they are equal
   */
  public static int compare(short a, short b) {
    return a - b; // safe due to restricted range
  }

  /**
   * Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.

            

Reported by PMD.

Do not use the short type
Performance

Line: 132

                 * @param target a primitive {@code short} value
   * @return {@code true} if {@code array[i] == target} for some value of {@code i}
   */
  public static boolean contains(short[] array, short target) {
    for (short value : array) {
      if (value == target) {
        return true;
      }
    }

            

Reported by PMD.

Do not use the short type
Performance

Line: 133

                 * @return {@code true} if {@code array[i] == target} for some value of {@code i}
   */
  public static boolean contains(short[] array, short target) {
    for (short value : array) {
      if (value == target) {
        return true;
      }
    }
    return false;

            

Reported by PMD.

Do not use the short type
Performance

Line: 149

                 * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
   *     such index exists.
   */
  public static int indexOf(short[] array, short target) {
    return indexOf(array, target, 0, array.length);
  }

  // TODO(kevinb): consider making this public
  private static int indexOf(short[] array, short target, int start, int end) {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java
46 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 403

                      };
  }

  abstract static class TransformedListMultimapGenerator
      extends TransformedMultimapGenerator<ListMultimap<String, String>>
      implements TestListMultimapGenerator<String, String> {}

  private static Test transformSuite() {
    TestSuite suite = new TestSuite("Multimaps.transform*");

            

Reported by PMD.

Avoid reassigning parameters such as 'multimap'
Design

Line: 621

                      ListMultimapTestSuiteBuilder.using(
                new FilteredListMultimapGenerator() {
                  @Override
                  ListMultimap<String, Integer> filter(ListMultimap<String, Integer> multimap) {
                    multimap.put("foo", 17);
                    multimap.put("bar", 32);
                    multimap.put("foo", 16);
                    multimap =
                        Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));

            

Reported by PMD.

Avoid reassigning parameters such as 'multimap'
Design

Line: 684

                      SetMultimapTestSuiteBuilder.using(
                new FilteredSetMultimapGenerator() {
                  @Override
                  SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
                    ImmutableSetMultimap<String, Integer> badEntries =
                        ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358);
                    multimap.putAll(badEntries);
                    multimap =
                        Multimaps.filterKeys(

            

Reported by PMD.

Avoid reassigning parameters such as 'multimap'
Design

Line: 707

                      SetMultimapTestSuiteBuilder.using(
                new FilteredSetMultimapGenerator() {
                  @Override
                  SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
                    ImmutableSetMultimap<String, Integer> badEntries =
                        ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358);
                    multimap.putAll(badEntries);
                    multimap =
                        Multimaps.filterEntries(

            

Reported by PMD.

Avoid reassigning parameters such as 'multimap'
Design

Line: 732

                      SetMultimapTestSuiteBuilder.using(
                new FilteredSetMultimapGenerator() {
                  @Override
                  SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
                    ImmutableSetMultimap<String, Integer> badEntries =
                        ImmutableSetMultimap.of("foo", 314, "bar", 358);
                    multimap.putAll(badEntries);
                    multimap =
                        Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));

            

Reported by PMD.

Avoid reassigning parameters such as 'multimap'
Design

Line: 732

                      SetMultimapTestSuiteBuilder.using(
                new FilteredSetMultimapGenerator() {
                  @Override
                  SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
                    ImmutableSetMultimap<String, Integer> badEntries =
                        ImmutableSetMultimap.of("foo", 314, "bar", 358);
                    multimap.putAll(badEntries);
                    multimap =
                        Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));

            

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.collect;

import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.testing.Helpers.mapEntry;
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES;
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 75

               * @author Jared Levy
 */
@GwtIncompatible // suite // TODO(cpovirk): set up collect/gwt/suites version
public class MultimapsCollectionTest extends TestCase {

  private static final Feature<?>[] FOR_MAP_FEATURES_ONE = {
    CollectionSize.ONE,
    ALLOWS_NULL_VALUES,
    SUPPORTS_REMOVE,

            

Reported by PMD.

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

Line: 96

                    new Supplier<TreeSet<String>>() {
        @Override
        public TreeSet<String> get() {
          return new TreeSet<>(Ordering.natural().nullsLast());
        }
      };

  static void populateMultimapForGet(Multimap<Integer, String> multimap, String[] elements) {
    multimap.put(2, "foo");

            

Reported by PMD.

The String literal 'foo' appears 18 times in this file; the first occurrence is on line 101
Error

Line: 101

                    };

  static void populateMultimapForGet(Multimap<Integer, String> multimap, String[] elements) {
    multimap.put(2, "foo");
    for (String element : elements) {
      multimap.put(3, element);
    }
  }


            

Reported by PMD.