The following issues were found

android/guava/src/com/google/common/util/concurrent/InterruptibleTask.java
20 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 35

              // Since this class only needs CAS on one field, we can avoid this bug by extending AtomicReference
// instead of using an AtomicReferenceFieldUpdater. This reference stores Thread instances
// and DONE/INTERRUPTED - they have a common ancestor of Runnable.
abstract class InterruptibleTask<T extends @Nullable Object>
    extends AtomicReference<@Nullable Runnable> implements Runnable {
  static {
    // Prevent rare disastrous classloading in first call to LockSupport.park.
    // See: https://bugs.openjdk.java.net/browse/JDK-8074773
    @SuppressWarnings("unused")

            

Reported by PMD.

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

Line: 76

                    if (run) {
        result = runInterruptibly();
      }
    } catch (Throwable t) {
      error = t;
    } finally {
      // Attempt to set the task as done so that further attempts to interrupt will fail.
      if (!compareAndSet(currentThread, DONE)) {
        waitForInterrupt(currentThread);

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 117

                  //                ||     ||
    Runnable state = get();
    Blocker blocker = null;
    while (state instanceof Blocker || state == PARKED) {
      if (state instanceof Blocker) {
        blocker = (Blocker) state;
      }
      spinCount++;
      if (spinCount > MAX_BUSY_WAIT_SPINS) {

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 130

                       * predictable what work might be done. (e.g., close a file and flush buffers to disk). To
         * protect ourselves from this, we park ourselves and tell our interrupter that we did so.
         */
        if (state == PARKED || compareAndSet(state, PARKED)) {
          // Interrupting Cow Says:
          //  ______
          // < Park >
          //  ------
          //        \   ^__^

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 171

                 * interrupted.
   */
  @ParametricNullness
  abstract T runInterruptibly() throws Exception;

  /**
   * Any interruption that happens as a result of calling interruptTask will arrive before this
   * method is called. Complete Futures here.
   */

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 206

                        ((Thread) currentRunner).interrupt();
        } finally {
          Runnable prev = getAndSet(DONE);
          if (prev == PARKED) {
            LockSupport.unpark((Thread) currentRunner);
          }
        }
      }
    }

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 220

                 * identify deadlocks.
   */
  @VisibleForTesting
  static final class Blocker extends AbstractOwnableSynchronizer implements Runnable {
    private final InterruptibleTask<?> task;

    private Blocker(InterruptibleTask<?> task) {
      this.task = task;
    }

            

Reported by PMD.

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

Line: 221

                 */
  @VisibleForTesting
  static final class Blocker extends AbstractOwnableSynchronizer implements Runnable {
    private final InterruptibleTask<?> task;

    private Blocker(InterruptibleTask<?> task) {
      this.task = task;
    }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 244

                public final String toString() {
    Runnable state = get();
    final String result;
    if (state == DONE) {
      result = "running=[DONE]";
    } else if (state instanceof Blocker) {
      result = "running=[INTERRUPTED]";
    } else if (state instanceof Thread) {
      // getName is final on Thread, no need to worry about exceptions

            

Reported by PMD.

Found 'DD'-anomaly for variable 'result' (lines '70'-'74').
Error

Line: 70

                  }

    boolean run = !isDone();
    T result = null;
    Throwable error = null;
    try {
      if (run) {
        result = runInterruptibly();
      }

            

Reported by PMD.

android/guava/src/com/google/common/eventbus/SubscriberRegistry.java
20 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.eventbus;

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


            

Reported by PMD.

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

Line: 69

                    Maps.newConcurrentMap();

  /** The event bus this registry belongs to. */
  @Weak private final EventBus bus;

  SubscriberRegistry(EventBus bus) {
    this.bus = checkNotNull(bus);
  }


            

Reported by PMD.

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

Line: 79

                void register(Object listener) {
    Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);

    for (Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
      Class<?> eventType = entry.getKey();
      Collection<Subscriber> eventMethodsInListener = entry.getValue();

      CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 86

                    CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);

      if (eventSubscribers == null) {
        CopyOnWriteArraySet<Subscriber> newSet = new CopyOnWriteArraySet<>();
        eventSubscribers =
            MoreObjects.firstNonNull(subscribers.putIfAbsent(eventType, newSet), newSet);
      }

      eventSubscribers.addAll(eventMethodsInListener);

            

Reported by PMD.

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

Line: 91

                          MoreObjects.firstNonNull(subscribers.putIfAbsent(eventType, newSet), newSet);
      }

      eventSubscribers.addAll(eventMethodsInListener);
    }
  }

  /** Unregisters all subscribers on the given listener object. */
  void unregister(Object listener) {

            

Reported by PMD.

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

Line: 99

                void unregister(Object listener) {
    Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);

    for (Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
      Class<?> eventType = entry.getKey();
      Collection<Subscriber> listenerMethodsForType = entry.getValue();

      CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
      if (currentSubscribers == null || !currentSubscribers.removeAll(listenerMethodsForType)) {

            

Reported by PMD.

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

Line: 104

                    Collection<Subscriber> listenerMethodsForType = entry.getValue();

      CopyOnWriteArraySet<Subscriber> currentSubscribers = subscribers.get(eventType);
      if (currentSubscribers == null || !currentSubscribers.removeAll(listenerMethodsForType)) {
        // if removeAll returns true, all we really know is that at least one subscriber was
        // removed... however, barring something very strange we can assume that if at least one
        // subscriber was removed, all subscribers on listener for that event type were... after
        // all, the definition of subscribers on a particular class is totally static
        throw new IllegalArgumentException(

            

Reported by PMD.

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

Line: 131

                  ImmutableSet<Class<?>> eventTypes = flattenHierarchy(event.getClass());

    List<Iterator<Subscriber>> subscriberIterators =
        Lists.newArrayListWithCapacity(eventTypes.size());

    for (Class<?> eventType : eventTypes) {
      CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);
      if (eventSubscribers != null) {
        // eager no-copy snapshot

            

Reported by PMD.

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

Line: 137

                    CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);
      if (eventSubscribers != null) {
        // eager no-copy snapshot
        subscriberIterators.add(eventSubscribers.iterator());
      }
    }

    return Iterators.concat(subscriberIterators.iterator());
  }

            

Reported by PMD.

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

Line: 141

                    }
    }

    return Iterators.concat(subscriberIterators.iterator());
  }

  /**
   * A thread-safe cache that contains the mapping from each class to all methods in that class and
   * all super-classes, that are annotated with {@code @Subscribe}. The cache is shared across all

            

Reported by PMD.

android/guava-tests/test/com/google/common/net/HostSpecifierTest.java
20 issues
Do not hard code the IP address
Design

Line: 38

              public final class HostSpecifierTest extends TestCase {

  private static final ImmutableList<String> GOOD_IPS =
      ImmutableList.of("1.2.3.4", "2001:db8::1", "[2001:db8::1]");

  private static final ImmutableList<String> BAD_IPS =
      ImmutableList.of("1.2.3", "2001:db8::1::::::0", "[2001:db8::1", "[::]:80");

  private static final ImmutableList<String> GOOD_DOMAINS =

            

Reported by PMD.

Do not hard code the IP address
Design

Line: 38

              public final class HostSpecifierTest extends TestCase {

  private static final ImmutableList<String> GOOD_IPS =
      ImmutableList.of("1.2.3.4", "2001:db8::1", "[2001:db8::1]");

  private static final ImmutableList<String> BAD_IPS =
      ImmutableList.of("1.2.3", "2001:db8::1::::::0", "[2001:db8::1", "[::]:80");

  private static final ImmutableList<String> GOOD_DOMAINS =

            

Reported by PMD.

The String literal 'google.com' appears 4 times in this file; the first occurrence is on line 44
Error

Line: 44

                    ImmutableList.of("1.2.3", "2001:db8::1::::::0", "[2001:db8::1", "[::]:80");

  private static final ImmutableList<String> GOOD_DOMAINS =
      ImmutableList.of("com", "google.com", "foo.co.uk");

  private static final ImmutableList<String> BAD_DOMAINS =
      ImmutableList.of("foo.blah", "", "[google.com]");

  public void testGoodIpAddresses() throws ParseException {

            

Reported by PMD.

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

Line: 49

                private static final ImmutableList<String> BAD_DOMAINS =
      ImmutableList.of("foo.blah", "", "[google.com]");

  public void testGoodIpAddresses() throws ParseException {
    for (String spec : GOOD_IPS) {
      assertGood(spec);
    }
  }


            

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

                  }
  }

  public void testBadIpAddresses() {
    for (String spec : BAD_IPS) {
      assertBad(spec);
    }
  }


            

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

                  }
  }

  public void testGoodDomains() throws ParseException {
    for (String spec : GOOD_DOMAINS) {
      assertGood(spec);
    }
  }


            

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 testBadDomains() {
    for (String spec : BAD_DOMAINS) {
      assertBad(spec);
    }
  }


            

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

                  }
  }

  public void testEquality() {
    new EqualsTester()
        .addEqualityGroup(spec("1.2.3.4"), spec("1.2.3.4"))
        .addEqualityGroup(spec("2001:db8::1"), spec("2001:db8::1"), spec("[2001:db8::1]"))
        .addEqualityGroup(spec("2001:db8::2"))
        .addEqualityGroup(spec("google.com"), spec("google.com"))

            

Reported by PMD.

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

Line: 73

                  }
  }

  public void testEquality() {
    new EqualsTester()
        .addEqualityGroup(spec("1.2.3.4"), spec("1.2.3.4"))
        .addEqualityGroup(spec("2001:db8::1"), spec("2001:db8::1"), spec("[2001:db8::1]"))
        .addEqualityGroup(spec("2001:db8::2"))
        .addEqualityGroup(spec("google.com"), spec("google.com"))

            

Reported by PMD.

Do not hard code the IP address
Design

Line: 75

              
  public void testEquality() {
    new EqualsTester()
        .addEqualityGroup(spec("1.2.3.4"), spec("1.2.3.4"))
        .addEqualityGroup(spec("2001:db8::1"), spec("2001:db8::1"), spec("[2001:db8::1]"))
        .addEqualityGroup(spec("2001:db8::2"))
        .addEqualityGroup(spec("google.com"), spec("google.com"))
        .addEqualityGroup(spec("www.google.com"))
        .testEquals();

            

Reported by PMD.

android/guava/src/com/google/common/graph/EndpointPair.java
20 issues
This class has too many methods, consider refactoring it.
Design

Line: 43

              @Beta
@Immutable(containerOf = {"N"})
@ElementTypesAreNonnullByDefault
public abstract class EndpointPair<N> implements Iterable<N> {
  private final N nodeU;
  private final N nodeV;

  private EndpointPair(N nodeU, N nodeV) {
    this.nodeU = checkNotNull(nodeU);

            

Reported by PMD.

Field nodeU has the same name as a method
Error

Line: 44

              @Immutable(containerOf = {"N"})
@ElementTypesAreNonnullByDefault
public abstract class EndpointPair<N> implements Iterable<N> {
  private final N nodeU;
  private final N nodeV;

  private EndpointPair(N nodeU, N nodeV) {
    this.nodeU = checkNotNull(nodeU);
    this.nodeV = checkNotNull(nodeV);

            

Reported by PMD.

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

Line: 44

              @Immutable(containerOf = {"N"})
@ElementTypesAreNonnullByDefault
public abstract class EndpointPair<N> implements Iterable<N> {
  private final N nodeU;
  private final N nodeV;

  private EndpointPair(N nodeU, N nodeV) {
    this.nodeU = checkNotNull(nodeU);
    this.nodeV = checkNotNull(nodeV);

            

Reported by PMD.

Field nodeV has the same name as a method
Error

Line: 45

              @ElementTypesAreNonnullByDefault
public abstract class EndpointPair<N> implements Iterable<N> {
  private final N nodeU;
  private final N nodeV;

  private EndpointPair(N nodeU, N nodeV) {
    this.nodeU = checkNotNull(nodeU);
    this.nodeV = checkNotNull(nodeV);
  }

            

Reported by PMD.

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

Line: 45

              @ElementTypesAreNonnullByDefault
public abstract class EndpointPair<N> implements Iterable<N> {
  private final N nodeU;
  private final N nodeV;

  private EndpointPair(N nodeU, N nodeV) {
    this.nodeU = checkNotNull(nodeU);
    this.nodeV = checkNotNull(nodeV);
  }

            

Reported by PMD.

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

Line: 177

                    }

      EndpointPair<?> other = (EndpointPair<?>) obj;
      if (isOrdered() != other.isOrdered()) {
        return false;
      }

      return source().equals(other.source()) && target().equals(other.target());
    }

            

Reported by PMD.

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

Line: 181

                      return false;
      }

      return source().equals(other.source()) && target().equals(other.target());
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(source(), target());

            

Reported by PMD.

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

Line: 181

                      return false;
      }

      return source().equals(other.source()) && target().equals(other.target());
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(source(), target());

            

Reported by PMD.

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

Line: 181

                      return false;
      }

      return source().equals(other.source()) && target().equals(other.target());
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(source(), target());

            

Reported by PMD.

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

Line: 181

                      return false;
      }

      return source().equals(other.source()) && target().equals(other.target());
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(source(), target());

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsEntryTester.java
20 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: 40

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapContainsEntryTester<K, V>
    extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(absent = ZERO)
  public void testContainsEntryYes() {
    assertTrue(multimap().containsEntry(k0(), v0()));
  }

  public void testContainsEntryNo() {

            

Reported by PMD.

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

Line: 42

                  extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(absent = ZERO)
  public void testContainsEntryYes() {
    assertTrue(multimap().containsEntry(k0(), v0()));
  }

  public void testContainsEntryNo() {
    assertFalse(multimap().containsEntry(k3(), v3()));
  }

            

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

                  assertTrue(multimap().containsEntry(k0(), v0()));
  }

  public void testContainsEntryNo() {
    assertFalse(multimap().containsEntry(k3(), v3()));
  }

  public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {

            

Reported by PMD.

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

Line: 46

                }

  public void testContainsEntryNo() {
    assertFalse(multimap().containsEntry(k3(), v3()));
  }

  public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {
      for (V v : sampleValues()) {

            

Reported by PMD.

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

Line: 49

                  assertFalse(multimap().containsEntry(k3(), v3()));
  }

  public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {
      for (V v : sampleValues()) {
        assertEquals(multimap().get(k).contains(v), multimap().containsEntry(k, v));
      }
    }

            

Reported by PMD.

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

Line: 52

                public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {
      for (V v : sampleValues()) {
        assertEquals(multimap().get(k).contains(v), multimap().containsEntry(k, v));
      }
    }
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 52

                public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {
      for (V v : sampleValues()) {
        assertEquals(multimap().get(k).contains(v), multimap().containsEntry(k, v));
      }
    }
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 52

                public void testContainsEntryAgreesWithGet() {
    for (K k : sampleKeys()) {
      for (V v : sampleValues()) {
        assertEquals(multimap().get(k).contains(v), multimap().containsEntry(k, v));
      }
    }
  }

  @CollectionSize.Require(absent = ZERO)

            

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

                  }
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
  public void testContainsEntryNullYes() {
    initMultimapWithNullKeyAndValue();
    assertTrue(multimap().containsEntry(null, null));
  }

            

Reported by PMD.

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

Line: 61

                @MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
  public void testContainsEntryNullYes() {
    initMultimapWithNullKeyAndValue();
    assertTrue(multimap().containsEntry(null, null));
  }

  @MapFeature.Require({ALLOWS_NULL_KEY_QUERIES, ALLOWS_NULL_VALUE_QUERIES})
  public void testContainsEntryNullNo() {
    assertFalse(multimap().containsEntry(null, null));

            

Reported by PMD.

android/guava-tests/test/com/google/common/reflect/ReflectionTest.java
20 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

              /** Tests for {@link Reflection} */
public class ReflectionTest extends TestCase {

  public void testGetPackageName() throws Exception {
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));

            

Reported by PMD.

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

Line: 28

              /** Tests for {@link Reflection} */
public class ReflectionTest extends TestCase {

  public void testGetPackageName() throws Exception {
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

              public class ReflectionTest extends TestCase {

  public void testGetPackageName() throws Exception {
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

              
  public void testGetPackageName() throws Exception {
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

                public void testGetPackageName() throws Exception {
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }

  public void testNewProxy() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

                  assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
    assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }

  public void testNewProxy() throws Exception {
    Runnable runnable = Reflection.newProxy(Runnable.class, X_RETURNER);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                  assertEquals("java", Reflection.getPackageName("java.MyType"));
    assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
    assertEquals("", Reflection.getPackageName("NoPackage"));
    assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }

  public void testNewProxy() throws Exception {
    Runnable runnable = Reflection.newProxy(Runnable.class, X_RETURNER);
    assertEquals("x", runnable.toString());

            

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

                  assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
  }

  public void testNewProxy() throws Exception {
    Runnable runnable = Reflection.newProxy(Runnable.class, X_RETURNER);
    assertEquals("x", runnable.toString());
  }

  public void testNewProxyCantWorkOnAClass() throws Exception {

            

Reported by PMD.

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

Line: 38

              
  public void testNewProxy() throws Exception {
    Runnable runnable = Reflection.newProxy(Runnable.class, X_RETURNER);
    assertEquals("x", runnable.toString());
  }

  public void testNewProxyCantWorkOnAClass() throws Exception {
    try {
      Reflection.newProxy(Object.class, X_RETURNER);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

              
  public void testNewProxy() throws Exception {
    Runnable runnable = Reflection.newProxy(Runnable.class, X_RETURNER);
    assertEquals("x", runnable.toString());
  }

  public void testNewProxyCantWorkOnAClass() throws Exception {
    try {
      Reflection.newProxy(Object.class, X_RETURNER);

            

Reported by PMD.

android/guava-tests/test/com/google/common/net/UrlEscapersTest.java
20 issues
Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 46

                  try {
      e.escape((String) null);
      fail("Escaping null string should throw exception");
    } catch (NullPointerException x) {
      // pass
    }

    // All URL escapers should leave 0-9, A-Z, a-z unescaped
    assertUnescaped(e, 'a');

            

Reported by PMD.

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

Line: 46

                  try {
      e.escape((String) null);
      fail("Escaping null string should throw exception");
    } catch (NullPointerException x) {
      // pass
    }

    // All URL escapers should leave 0-9, A-Z, a-z unescaped
    assertUnescaped(e, 'a');

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 46

                  try {
      e.escape((String) null);
      fail("Escaping null string should throw exception");
    } catch (NullPointerException x) {
      // pass
    }

    // All URL escapers should leave 0-9, A-Z, a-z unescaped
    assertUnescaped(e, 'a');

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 73

                  assertUnicodeEscaping(e, "%F0%90%80%80", '\uD800', '\uDC00');
    assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF');

    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 74

                  assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF');

    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  // Helper to assert common expected behaviour of uri escapers.

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 75

              
    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  // Helper to assert common expected behaviour of uri escapers.
  static void assertBasicUrlEscaper(UnicodeEscaper e) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 76

                  assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  // Helper to assert common expected behaviour of uri escapers.
  static void assertBasicUrlEscaper(UnicodeEscaper e) {
    assertBasicUrlEscaperExceptPercent(e);

            

Reported by PMD.

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

Line: 86

                  assertEscaping(e, "%25", '%');
  }

  public void testUrlFormParameterEscaper() {
    UnicodeEscaper e = (UnicodeEscaper) urlFormParameterEscaper();
    // Verify that these are the same escaper (as documented)
    assertSame(e, urlFormParameterEscaper());
    assertBasicUrlEscaper(e);


            

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

                  assertEscaping(e, "%25", '%');
  }

  public void testUrlFormParameterEscaper() {
    UnicodeEscaper e = (UnicodeEscaper) urlFormParameterEscaper();
    // Verify that these are the same escaper (as documented)
    assertSame(e, urlFormParameterEscaper());
    assertBasicUrlEscaper(e);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 89

                public void testUrlFormParameterEscaper() {
    UnicodeEscaper e = (UnicodeEscaper) urlFormParameterEscaper();
    // Verify that these are the same escaper (as documented)
    assertSame(e, urlFormParameterEscaper());
    assertBasicUrlEscaper(e);

    /*
     * Specified as safe by RFC 2396 but not by java.net.URLEncoder. These tests will start failing
     * when the escaper is made compliant with RFC 2396, but that's a good thing (just change them

            

Reported by PMD.

android/guava/src/com/google/common/primitives/Doubles.java
20 issues
Avoid using a branching statement as the last in a loop.
Error

Line: 175

                        continue outer;
        }
      }
      return i;
    }
    return -1;
  }

  /**

            

Reported by PMD.

Possible God Class (WMC=51, ATFD=27, TCC=0.000%)
Design

Line: 51

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Doubles extends DoublesMethodsForWeb {
  private Doubles() {}

  /**
   * The number of bytes required to represent a primitive {@code double} value.
   *

            

Reported by PMD.

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

Line: 51

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Doubles extends DoublesMethodsForWeb {
  private Doubles() {}

  /**
   * The number of bytes required to represent a primitive {@code double} value.
   *

            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 463

                public static void reverse(double[] array, int fromIndex, int toIndex) {
    checkNotNull(array);
    checkPositionIndexes(fromIndex, toIndex, array.length);
    for (int i = fromIndex, j = toIndex - 1; i < j; i++, j--) {
      double tmp = array[i];
      array[i] = array[j];
      array[j] = tmp;
    }
  }

            

Reported by PMD.

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

Line: 526

                @GwtCompatible
  private static class DoubleArrayAsList extends AbstractList<Double>
      implements RandomAccess, Serializable {
    final double[] array;
    final int start;
    final int end;

    DoubleArrayAsList(double[] array) {
      this(array, 0, array.length);

            

Reported by PMD.

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

Line: 527

                private static class DoubleArrayAsList extends AbstractList<Double>
      implements RandomAccess, Serializable {
    final double[] array;
    final int start;
    final int end;

    DoubleArrayAsList(double[] array) {
      this(array, 0, array.length);
    }

            

Reported by PMD.

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

Line: 528

                    implements RandomAccess, Serializable {
    final double[] array;
    final int start;
    final int end;

    DoubleArrayAsList(double[] array) {
      this(array, 0, array.length);
    }


            

Reported by PMD.

The user-supplied array 'array' is stored directly.
Design

Line: 534

                    this(array, 0, array.length);
    }

    DoubleArrayAsList(double[] array, int start, int end) {
      this.array = array;
      this.start = start;
      this.end = end;
    }


            

Reported by PMD.

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

Line: 614

                    if (object instanceof DoubleArrayAsList) {
        DoubleArrayAsList that = (DoubleArrayAsList) object;
        int size = size();
        if (that.size() != size) {
          return false;
        }
        for (int i = 0; i < size; i++) {
          if (array[start + i] != that.array[that.start + i]) {
            return false;

            

Reported by PMD.

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

Line: 678

                  String completeHex = "0[xX]" + hex + "[pP][+-]?\\d+#[fFdD]?";
    String fpPattern = "[+-]?(?:NaN|Infinity|" + completeDec + "|" + completeHex + ")";
    fpPattern =
        fpPattern.replace(
            "#",
            "+"
            );
    return
    java.util.regex.Pattern

            

Reported by PMD.

guava-tests/test/com/google/common/collect/CompactLinkedHashSetTest.java
20 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 42

               */
@GwtIncompatible // java.util.Arrays#copyOf(Object[], int), java.lang.reflect.Array
public class CompactLinkedHashSetTest extends TestCase {
  public static Test suite() {
    List<Feature<?>> allFeatures =
        Arrays.<Feature<?>>asList(
            CollectionSize.ANY,
            CollectionFeature.ALLOWS_NULL_VALUES,
            CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 75

                                @Override
                  protected Set<String> create(String[] elements) {
                    CompactLinkedHashSet<String> set = CompactLinkedHashSet.create();
                    set.convertToHashFloodingResistantImplementation();
                    Collections.addAll(set, elements);
                    return set;
                  }
                })
            .named("CompactLinkedHashSet with flooding protection")

            

Reported by PMD.

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

Line: 86

                  return suite;
  }

  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);

            

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

                  return suite;
  }

  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);

            

Reported by PMD.

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

Line: 88

              
  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);

            

Reported by PMD.

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

Line: 88

              
  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);

            

Reported by PMD.

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

Line: 89

                public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

            

Reported by PMD.

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

Line: 91

                  assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

  public void testAllocArraysExpectedSize() {

            

Reported by PMD.

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

Line: 92

                  assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

  public void testAllocArraysExpectedSize() {
    for (int i = 0; i <= CompactHashing.DEFAULT_SIZE; i++) {

            

Reported by PMD.

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

Line: 92

                  assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

  public void testAllocArraysExpectedSize() {
    for (int i = 0; i <= CompactHashing.DEFAULT_SIZE; i++) {

            

Reported by PMD.

guava-testlib/test/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilderTest.java
20 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 32

              
  static boolean testWasRun;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    testWasRun = false;
  }


            

Reported by PMD.

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

Line: 40

              
  @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
  public static final class MyAbstractTester extends AbstractTester<Void> {
    public void testNothing() {
      testWasRun = true;
    }
  }

  private static final class MyTestSuiteBuilder

            

Reported by PMD.

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

Line: 40

              
  @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
  public static final class MyAbstractTester extends AbstractTester<Void> {
    public void testNothing() {
      testWasRun = true;
    }
  }

  private static final class MyTestSuiteBuilder

            

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

                  }
  }

  public void testLifecycle() {
    final boolean setUp[] = {false};
    Runnable setUpRunnable =
        new Runnable() {
          @Override
          public void run() {

            

Reported by PMD.

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

Line: 54

                  }
  }

  public void testLifecycle() {
    final boolean setUp[] = {false};
    Runnable setUpRunnable =
        new Runnable() {
          @Override
          public void run() {

            

Reported by PMD.

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

Line: 75

              
    MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
    Test test =
        builder
            .usingGenerator("yam")
            .named("yam")
            .withFeatures(CollectionFeature.NONE)
            .withSetUp(setUpRunnable)
            .withTearDown(tearDownRunnable)

            

Reported by PMD.

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

Line: 75

              
    MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
    Test test =
        builder
            .usingGenerator("yam")
            .named("yam")
            .withFeatures(CollectionFeature.NONE)
            .withSetUp(setUpRunnable)
            .withTearDown(tearDownRunnable)

            

Reported by PMD.

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

Line: 75

              
    MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
    Test test =
        builder
            .usingGenerator("yam")
            .named("yam")
            .withFeatures(CollectionFeature.NONE)
            .withSetUp(setUpRunnable)
            .withTearDown(tearDownRunnable)

            

Reported by PMD.

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

Line: 75

              
    MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
    Test test =
        builder
            .usingGenerator("yam")
            .named("yam")
            .withFeatures(CollectionFeature.NONE)
            .withSetUp(setUpRunnable)
            .withTearDown(tearDownRunnable)

            

Reported by PMD.

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

Line: 75

              
    MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
    Test test =
        builder
            .usingGenerator("yam")
            .named("yam")
            .withFeatures(CollectionFeature.NONE)
            .withSetUp(setUpRunnable)
            .withTearDown(tearDownRunnable)

            

Reported by PMD.