The following issues were found

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

Line: 157

                        @Override
          public void run() {
            numCalls.incrementAndGet();
            throw new RuntimeException("FAKE EXCEPTION!");
          }
        };

    e.execute(runMe);
    e.execute(runMe);

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 299

                            try {
                barrier.await();
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
            }
          };
      executor.execute(errorTask);
      service.execute(barrierTask); // submit directly to the service

            

Reported by PMD.

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

Line: 46

               *
 * @author JJ Furman
 */
public class SequentialExecutorTest extends TestCase {

  private static class FakeExecutor implements Executor {
    Queue<Runnable> tasks = Queues.newArrayDeque();

    @Override

            

Reported by PMD.

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

Line: 49

              public class SequentialExecutorTest extends TestCase {

  private static class FakeExecutor implements Executor {
    Queue<Runnable> tasks = Queues.newArrayDeque();

    @Override
    public void execute(Runnable command) {
      tasks.add(command);
    }

            

Reported by PMD.

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

Line: 62

              
    void runNext() {
      assertTrue("expected at least one task to run", hasNext());
      tasks.remove().run();
    }

    void runAll() {
      while (hasNext()) {
        runNext();

            

Reported by PMD.

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

Line: 72

                  }
  }

  private FakeExecutor fakePool;
  private SequentialExecutor e;

  @Override
  public void setUp() {
    fakePool = new FakeExecutor();

            

Reported by PMD.

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

Line: 73

                }

  private FakeExecutor fakePool;
  private SequentialExecutor e;

  @Override
  public void setUp() {
    fakePool = new FakeExecutor();
    e = new SequentialExecutor(fakePool);

            

Reported by PMD.

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

Line: 75

                private FakeExecutor fakePool;
  private SequentialExecutor e;

  @Override
  public void setUp() {
    fakePool = new FakeExecutor();
    e = new SequentialExecutor(fakePool);
  }


            

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

                  e = new SequentialExecutor(fakePool);
  }

  public void testConstructingWithNullExecutor_fails() {
    try {
      new SequentialExecutor(null);
      fail("Should have failed with NullPointerException.");
    } catch (NullPointerException expected) {
    }

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 84

                public void testConstructingWithNullExecutor_fails() {
    try {
      new SequentialExecutor(null);
      fail("Should have failed with NullPointerException.");
    } catch (NullPointerException expected) {
    }
  }

  public void testBasics() {

            

Reported by PMD.

guava-tests/test/com/google/common/graph/AbstractGraphTest.java
115 issues
The class 'AbstractGraphTest' has a Standard Cyclomatic Complexity of 1 (Highest = 10).
Design

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 52

               */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case
   * {@link #createGraph()} didn't return a mutable graph.
   */

            

Reported by PMD.

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

Line: 58

                 * The same reference as {@link #graph}, except as a mutable graph. This field is null in case
   * {@link #createGraph()} didn't return a mutable graph.
   */
  MutableGraph<Integer> graphAsMutableGraph;

  static final Integer N1 = 1;
  static final Integer N2 = 2;
  static final Integer N3 = 3;
  static final Integer N4 = 4;

            

Reported by PMD.

The method 'validateGraph' has a Standard Cyclomatic Complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

The method 'validateGraph(Graph)' has a cyclomatic complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

The method 'validateGraph' has a Modified Cyclomatic Complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

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

Line: 115

                  assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());
    assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops());

    int nodeStart = graphString.indexOf("nodes:");
    int edgeStart = graphString.indexOf("edges:");
    String nodeString = graphString.substring(nodeStart, edgeStart);

            

Reported by PMD.

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

Line: 116

              
    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());
    assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops());

    int nodeStart = graphString.indexOf("nodes:");
    int edgeStart = graphString.indexOf("edges:");
    String nodeString = graphString.substring(nodeStart, edgeStart);


            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/AbstractGraphTest.java
115 issues
The class 'AbstractGraphTest' has a Standard Cyclomatic Complexity of 1 (Highest = 10).
Design

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 50

               * TODO(user): Make this class generic (using <N, E>) for all node and edge types.
 * TODO(user): Differentiate between directed and undirected edge strings.
 */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case

            

Reported by PMD.

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

Line: 52

               */
public abstract class AbstractGraphTest {

  Graph<Integer> graph;

  /**
   * The same reference as {@link #graph}, except as a mutable graph. This field is null in case
   * {@link #createGraph()} didn't return a mutable graph.
   */

            

Reported by PMD.

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

Line: 58

                 * The same reference as {@link #graph}, except as a mutable graph. This field is null in case
   * {@link #createGraph()} didn't return a mutable graph.
   */
  MutableGraph<Integer> graphAsMutableGraph;

  static final Integer N1 = 1;
  static final Integer N2 = 2;
  static final Integer N3 = 3;
  static final Integer N4 = 4;

            

Reported by PMD.

The method 'validateGraph' has a Modified Cyclomatic Complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

The method 'validateGraph(Graph)' has a cyclomatic complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

The method 'validateGraph' has a Standard Cyclomatic Complexity of 10.
Design

Line: 110

                  validateGraph(graph);
  }

  static <N> void validateGraph(Graph<N> graph) {
    assertStronglyEquivalent(graph, Graphs.copyOf(graph));
    assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());

            

Reported by PMD.

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

Line: 115

                  assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));

    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());
    assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops());

    int nodeStart = graphString.indexOf("nodes:");
    int edgeStart = graphString.indexOf("edges:");
    String nodeString = graphString.substring(nodeStart, edgeStart);

            

Reported by PMD.

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

Line: 116

              
    String graphString = graph.toString();
    assertThat(graphString).contains("isDirected: " + graph.isDirected());
    assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops());

    int nodeStart = graphString.indexOf("nodes:");
    int edgeStart = graphString.indexOf("edges:");
    String nodeString = graphString.substring(nodeStart, edgeStart);


            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/Monitor.java
114 issues
Avoid reassigning parameters such as 'nanos'
Design

Line: 1100

              
  /** Caller should check before calling that guard is not satisfied. */
  @GuardedBy("lock")
  private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
      throws InterruptedException {
    boolean firstTime = true;
    try {
      do {
        if (nanos <= 0L) {

            

Reported by PMD.

The class 'Monitor' has a Standard Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 204

              @GwtIncompatible
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
@ElementTypesAreNonnullByDefault
public final class Monitor {
  // TODO(user): Use raw LockSupport or AbstractQueuedSynchronizer instead of ReentrantLock.
  // TODO(user): "Port" jsr166 tests for ReentrantLock.
  //
  // TODO(user): Change API to make it impossible to use a Guard with the "wrong" monitor,
  //    by making the monitor implicit, and to eliminate other sources of IMSE.

            

Reported by PMD.

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

Line: 204

              @GwtIncompatible
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
@ElementTypesAreNonnullByDefault
public final class Monitor {
  // TODO(user): Use raw LockSupport or AbstractQueuedSynchronizer instead of ReentrantLock.
  // TODO(user): "Port" jsr166 tests for ReentrantLock.
  //
  // TODO(user): Change API to make it impossible to use a Guard with the "wrong" monitor,
  //    by making the monitor implicit, and to eliminate other sources of IMSE.

            

Reported by PMD.

The class 'Monitor' has a Modified Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 204

              @GwtIncompatible
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
@ElementTypesAreNonnullByDefault
public final class Monitor {
  // TODO(user): Use raw LockSupport or AbstractQueuedSynchronizer instead of ReentrantLock.
  // TODO(user): "Port" jsr166 tests for ReentrantLock.
  //
  // TODO(user): Change API to make it impossible to use a Guard with the "wrong" monitor,
  //    by making the monitor implicit, and to eliminate other sources of IMSE.

            

Reported by PMD.

The class 'Monitor' has a total cyclomatic complexity of 139 (highest 14).
Design

Line: 204

              @GwtIncompatible
@SuppressWarnings("GuardedBy") // TODO(b/35466881): Fix or suppress.
@ElementTypesAreNonnullByDefault
public final class Monitor {
  // TODO(user): Use raw LockSupport or AbstractQueuedSynchronizer instead of ReentrantLock.
  // TODO(user): "Port" jsr166 tests for ReentrantLock.
  //
  // TODO(user): Change API to make it impossible to use a Guard with the "wrong" monitor,
  //    by making the monitor implicit, and to eliminate other sources of IMSE.

            

Reported by PMD.

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

Line: 307

                @Beta
  public abstract static class Guard {

    @Weak final Monitor monitor;
    final Condition condition;

    @GuardedBy("monitor.lock")
    int waiterCount = 0;


            

Reported by PMD.

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

Line: 308

                public abstract static class Guard {

    @Weak final Monitor monitor;
    final Condition condition;

    @GuardedBy("monitor.lock")
    int waiterCount = 0;

    /** The next active guard */

            

Reported by PMD.

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

Line: 311

                  final Condition condition;

    @GuardedBy("monitor.lock")
    int waiterCount = 0;

    /** The next active guard */
    @GuardedBy("monitor.lock")
    @CheckForNull
    Guard next;

            

Reported by PMD.

Avoid using redundant field initializer for 'waiterCount'
Performance

Line: 311

                  final Condition condition;

    @GuardedBy("monitor.lock")
    int waiterCount = 0;

    /** The next active guard */
    @GuardedBy("monitor.lock")
    @CheckForNull
    Guard next;

            

Reported by PMD.

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

Line: 316

                  /** The next active guard */
    @GuardedBy("monitor.lock")
    @CheckForNull
    Guard next;

    protected Guard(Monitor monitor) {
      this.monitor = checkNotNull(monitor, "monitor");
      this.condition = monitor.lock.newCondition();
    }

            

Reported by PMD.

guava-tests/test/com/google/common/base/ConverterTest.java
113 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

              
/** Unit tests for {@link Converter}. */
@GwtCompatible
public class ConverterTest extends TestCase {

  private static final Converter<String, Long> STR_TO_LONG =
      new Converter<String, Long>() {
        @Override
        protected Long doForward(String object) {

            

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

                private static final ImmutableList<String> STRINGS = ImmutableList.of("123", "456");
  private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));

            

Reported by PMD.

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

Line: 59

                private static final ImmutableList<String> STRINGS = ImmutableList.of("123", "456");
  private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

              
  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }


            

Reported by PMD.

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

Line: 61

              
  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);

            

Reported by PMD.

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

Line: 67

                  assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();

            

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

                  assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 70

                public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();
    iterator.next();
    iterator.remove();
    assertEquals(ImmutableList.of("123"), mutableList);

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/AbstractFuture.java
113 issues
Avoid throwing raw exception types.
Design

Line: 1346

                                  }
                  });
        } catch (PrivilegedActionException e) {
          throw new RuntimeException("Could not initialize intrinsics", e.getCause());
        }
      }
      try {
        Class<?> abstractFuture = AbstractFuture.class;
        WAITERS_OFFSET = unsafe.objectFieldOffset(abstractFuture.getDeclaredField("waiters"));

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 1359

                      UNSAFE = unsafe;
      } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
      }
    }

    @Override
    void putThread(Waiter waiter, Thread newValue) {

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 271

                      }
        curr = succ;
      }
      break;
    }
  }

  /** Listeners also form a stack through the {@link #listeners} field. */
  private static final class Listener {

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 1041

                        executeListener(task, requireNonNull(curr.executor));
        }
      }
      break;
    }
  }

  /**
   * Callback method that is called exactly once after the future is completed.

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 1282

                    // Log it and keep going -- bad runnable and/or executor. Don't punish the other runnables if
      // we're given a bad one. We only catch RuntimeException because we want Errors to propagate
      // up.
      log.log(
          Level.SEVERE,
          "RuntimeException while executing runnable " + runnable + " with executor " + executor,
          e);
    }
  }

            

Reported by PMD.

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

Line: 15

               * the License.
 */

package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.util.concurrent.NullnessCasts.uncheckedNull;
import static java.lang.Integer.toHexString;

            

Reported by PMD.

The class 'AbstractFuture' has a Standard Cyclomatic Complexity of 5 (Highest = 20).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

The class 'AbstractFuture' has a total cyclomatic complexity of 145 (highest 25).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

The class 'AbstractFuture' has a Modified Cyclomatic Complexity of 5 (Highest = 20).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

Possible God Class (WMC=145, ATFD=54, TCC=25.616%)
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

android/guava-tests/test/com/google/common/base/ConverterTest.java
113 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

              
/** Unit tests for {@link Converter}. */
@GwtCompatible
public class ConverterTest extends TestCase {

  private static final Converter<String, Long> STR_TO_LONG =
      new Converter<String, Long>() {
        @Override
        protected Long doForward(String object) {

            

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

                private static final ImmutableList<String> STRINGS = ImmutableList.of("123", "456");
  private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));

            

Reported by PMD.

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

Line: 59

                private static final ImmutableList<String> STRINGS = ImmutableList.of("123", "456");
  private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                private static final ImmutableList<Long> LONGS = ImmutableList.of(123L, 456L);

  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

              
  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }


            

Reported by PMD.

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

Line: 61

              
  public void testConverter() {
    assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL));
    assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL));

    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS);
    assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);

            

Reported by PMD.

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

Line: 67

                  assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();

            

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

                  assertEquals(LONGS, ImmutableList.copyOf(convertedValues));
  }

  public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 70

                public void testConvertAllIsView() {
    List<String> mutableList = Lists.newArrayList("789", "123");
    Iterable<Long> convertedValues = STR_TO_LONG.convertAll(mutableList);
    assertEquals(ImmutableList.of(789L, 123L), ImmutableList.copyOf(convertedValues));

    Iterator<Long> iterator = convertedValues.iterator();
    iterator.next();
    iterator.remove();
    assertEquals(ImmutableList.of("123"), mutableList);

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/AbstractFuture.java
113 issues
Avoid throwing raw exception types.
Design

Line: 1346

                                  }
                  });
        } catch (PrivilegedActionException e) {
          throw new RuntimeException("Could not initialize intrinsics", e.getCause());
        }
      }
      try {
        Class<?> abstractFuture = AbstractFuture.class;
        WAITERS_OFFSET = unsafe.objectFieldOffset(abstractFuture.getDeclaredField("waiters"));

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 1359

                      UNSAFE = unsafe;
      } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
      }
    }

    @Override
    void putThread(Waiter waiter, Thread newValue) {

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 271

                      }
        curr = succ;
      }
      break;
    }
  }

  /** Listeners also form a stack through the {@link #listeners} field. */
  private static final class Listener {

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 1041

                        executeListener(task, requireNonNull(curr.executor));
        }
      }
      break;
    }
  }

  /**
   * Callback method that is called exactly once after the future is completed.

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 1282

                    // Log it and keep going -- bad runnable and/or executor. Don't punish the other runnables if
      // we're given a bad one. We only catch RuntimeException because we want Errors to propagate
      // up.
      log.log(
          Level.SEVERE,
          "RuntimeException while executing runnable " + runnable + " with executor " + executor,
          e);
    }
  }

            

Reported by PMD.

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

Line: 15

               * the License.
 */

package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.util.concurrent.NullnessCasts.uncheckedNull;
import static java.lang.Integer.toHexString;

            

Reported by PMD.

The class 'AbstractFuture' has a Standard Cyclomatic Complexity of 5 (Highest = 20).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

The class 'AbstractFuture' has a total cyclomatic complexity of 145 (highest 25).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

Avoid really long classes.
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

The class 'AbstractFuture' has a Modified Cyclomatic Complexity of 5 (Highest = 20).
Design

Line: 77

              @GwtCompatible(emulated = true)
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
@ElementTypesAreNonnullByDefault
public abstract class AbstractFuture<V extends @Nullable Object> extends InternalFutureFailureAccess
    implements ListenableFuture<V> {
  // NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||

  private static final boolean GENERATE_CANCELLATION_CAUSES;


            

Reported by PMD.

guava-tests/test/com/google/common/primitives/UnsignedLongTest.java
112 issues
This class has too many methods, consider refactoring it.
Design

Line: 32

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class UnsignedLongTest extends TestCase {
  private static final ImmutableSet<Long> TEST_LONGS;
  private static final ImmutableSet<BigInteger> TEST_BIG_INTEGERS;

  static {
    ImmutableSet.Builder<Long> testLongsBuilder = ImmutableSet.builder();

            

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

                  TEST_BIG_INTEGERS = testBigIntegersBuilder.build();
  }

  public void testAsUnsignedAndLongValueAreInverses() {
    for (long value : TEST_LONGS) {
      assertEquals(
          UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue());
    }
  }

            

Reported by PMD.

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

Line: 73

                public void testAsUnsignedAndLongValueAreInverses() {
    for (long value : TEST_LONGS) {
      assertEquals(
          UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue());
    }
  }

  public void testAsUnsignedBigIntegerValue() {
    for (long value : TEST_LONGS) {

            

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

                  }
  }

  public void testAsUnsignedBigIntegerValue() {
    for (long value : TEST_LONGS) {
      BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));

            

Reported by PMD.

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

Line: 82

                    BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));
      assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }

            

Reported by PMD.

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

Line: 82

                    BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));
      assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }

            

Reported by PMD.

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

Line: 86

                    assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {

            

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

                  }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);

            

Reported by PMD.

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

Line: 90

                  }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);

            

Reported by PMD.

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

Line: 94

                  for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);
      } catch (IllegalArgumentException e) {
        assertFalse(expectSuccess);
      }
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/primitives/UnsignedLongTest.java
112 issues
This class has too many methods, consider refactoring it.
Design

Line: 32

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class UnsignedLongTest extends TestCase {
  private static final ImmutableSet<Long> TEST_LONGS;
  private static final ImmutableSet<BigInteger> TEST_BIG_INTEGERS;

  static {
    ImmutableSet.Builder<Long> testLongsBuilder = ImmutableSet.builder();

            

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

                  TEST_BIG_INTEGERS = testBigIntegersBuilder.build();
  }

  public void testAsUnsignedAndLongValueAreInverses() {
    for (long value : TEST_LONGS) {
      assertEquals(
          UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue());
    }
  }

            

Reported by PMD.

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

Line: 73

                public void testAsUnsignedAndLongValueAreInverses() {
    for (long value : TEST_LONGS) {
      assertEquals(
          UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue());
    }
  }

  public void testAsUnsignedBigIntegerValue() {
    for (long value : TEST_LONGS) {

            

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

                  }
  }

  public void testAsUnsignedBigIntegerValue() {
    for (long value : TEST_LONGS) {
      BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));

            

Reported by PMD.

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

Line: 82

                    BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));
      assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }

            

Reported by PMD.

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

Line: 82

                    BigInteger expected =
          (value >= 0)
              ? BigInteger.valueOf(value)
              : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64));
      assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }

            

Reported by PMD.

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

Line: 86

                    assertEquals(
          UnsignedLongs.toString(value),
          expected,
          UnsignedLong.fromLongBits(value).bigIntegerValue());
    }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {

            

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

                  }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);

            

Reported by PMD.

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

Line: 90

                  }
  }

  public void testValueOfLong() {
    for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 94

                  for (long value : TEST_LONGS) {
      boolean expectSuccess = value >= 0;
      try {
        assertEquals(value, UnsignedLong.valueOf(value).longValue());
        assertTrue(expectSuccess);
      } catch (IllegalArgumentException e) {
        assertFalse(expectSuccess);
      }
    }

            

Reported by PMD.