The following issues were found

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

Line: 36

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }

            

Reported by PMD.

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

Line: 37

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }


            

Reported by PMD.

Field endpoint has the same name as a method
Error

Line: 37

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class Cut<C extends Comparable> implements Comparable<Cut<C>>, Serializable {
  final C endpoint;

  Cut(C endpoint) {
    this.endpoint = endpoint;
  }


            

Reported by PMD.

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

Line: 123

              
  private static final long serialVersionUID = 0;

  private static final class BelowAll extends Cut<Comparable<?>> {
    private static final BelowAll INSTANCE = new BelowAll();

    private BelowAll() {
      /*
       * No code ever sees this bogus value for `endpoint`: This class overrides both methods that

            

Reported by PMD.

The String literal 'this statement should be unreachable' appears 4 times in this file; the first occurrence is on line 153
Error

Line: 153

              
    @Override
    BoundType typeAsUpperBound() {
      throw new AssertionError("this statement should be unreachable");
    }

    @Override
    Cut<Comparable<?>> withLowerBoundType(
        BoundType boundType, DiscreteDomain<Comparable<?>> domain) {

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 199

              
    @Override
    public int compareTo(Cut<Comparable<?>> o) {
      return (o == this) ? 0 : -1;
    }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);

            

Reported by PMD.

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

Line: 228

                  return (Cut<C>) AboveAll.INSTANCE;
  }

  private static final class AboveAll extends Cut<Comparable<?>> {
    private static final AboveAll INSTANCE = new AboveAll();

    private AboveAll() {
      // For discussion of "", see BelowAll.
      super("");

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 290

              
    @Override
    public int compareTo(Cut<Comparable<?>> o) {
      return (o == this) ? 0 : 1;
    }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);

            

Reported by PMD.

Ensure you override both equals() and hashCode()
Error

Line: 294

                  }

    @Override
    public int hashCode() {
      return System.identityHashCode(this);
    }

    @Override
    public String toString() {

            

Reported by PMD.

Ensure you override both equals() and hashCode()
Error

Line: 382

                  }

    @Override
    public int hashCode() {
      return endpoint.hashCode();
    }

    @Override
    public String toString() {

            

Reported by PMD.

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableCollection.java
12 issues
Return an empty array rather than null.
Error

Line: 93

                }

  /** If this collection is backed by an array of its elements in insertion order, returns it. */
  Object @Nullable [] internalArray() {
    return null;
  }

  /**
   * If this collection is backed by an array of its elements in insertion order, returns the offset

            

Reported by PMD.

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

Line: 35

               * @author Jesse Wilson
 */
@SuppressWarnings("serial") // we're overriding default serialization
public abstract class ImmutableCollection<E> extends AbstractCollection<E> implements Serializable {
  static final int SPLITERATOR_CHARACTERISTICS =
      Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED;

  static final ImmutableCollection<Object> EMPTY_IMMUTABLE_COLLECTION =
      new ForwardingImmutableCollection<Object>(Collections.emptyList());

            

Reported by PMD.

The method 'iterator()' is missing an @Override annotation.
Design

Line: 44

              
  ImmutableCollection() {}

  public abstract UnmodifiableIterator<E> iterator();

  public boolean contains(@Nullable Object object) {
    return object != null && super.contains(object);
  }


            

Reported by PMD.

The method 'contains(Object)' is missing an @Override annotation.
Design

Line: 46

              
  public abstract UnmodifiableIterator<E> iterator();

  public boolean contains(@Nullable Object object) {
    return object != null && super.contains(object);
  }

  public final boolean add(E e) {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'add(E)' is missing an @Override annotation.
Design

Line: 50

                  return object != null && super.contains(object);
  }

  public final boolean add(E e) {
    throw new UnsupportedOperationException();
  }

  public final boolean remove(Object object) {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'remove(Object)' is missing an @Override annotation.
Design

Line: 54

                  throw new UnsupportedOperationException();
  }

  public final boolean remove(Object object) {
    throw new UnsupportedOperationException();
  }

  public final boolean addAll(Collection<? extends E> newElements) {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'addAll(Collection)' is missing an @Override annotation.
Design

Line: 58

                  throw new UnsupportedOperationException();
  }

  public final boolean addAll(Collection<? extends E> newElements) {
    throw new UnsupportedOperationException();
  }

  public final boolean removeAll(Collection<?> oldElements) {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'removeAll(Collection)' is missing an @Override annotation.
Design

Line: 62

                  throw new UnsupportedOperationException();
  }

  public final boolean removeAll(Collection<?> oldElements) {
    throw new UnsupportedOperationException();
  }

  public final boolean retainAll(Collection<?> elementsToKeep) {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'retainAll(Collection)' is missing an @Override annotation.
Design

Line: 66

                  throw new UnsupportedOperationException();
  }

  public final boolean retainAll(Collection<?> elementsToKeep) {
    throw new UnsupportedOperationException();
  }

  public final void clear() {
    throw new UnsupportedOperationException();

            

Reported by PMD.

The method 'clear()' is missing an @Override annotation.
Design

Line: 70

                  throw new UnsupportedOperationException();
  }

  public final void clear() {
    throw new UnsupportedOperationException();
  }

  private transient ImmutableList<E> asList;


            

Reported by PMD.

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

Line: 56

              
  private static class SupplierComposition<F extends @Nullable Object, T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Function<? super F, T> function;
    final Supplier<F> supplier;

    SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
      this.function = checkNotNull(function);
      this.supplier = checkNotNull(supplier);

            

Reported by PMD.

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

Line: 57

                private static class SupplierComposition<F extends @Nullable Object, T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Function<? super F, T> function;
    final Supplier<F> supplier;

    SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
      this.function = checkNotNull(function);
      this.supplier = checkNotNull(supplier);
    }

            

Reported by PMD.

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

Line: 120

              
  @VisibleForTesting
  static class MemoizingSupplier<T extends @Nullable Object> implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    transient volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull transient T value;


            

Reported by PMD.

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

Line: 160

              
  @VisibleForTesting
  static class NonSerializableMemoizingSupplier<T extends @Nullable Object> implements Supplier<T> {
    @CheckForNull volatile Supplier<T> delegate;
    volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;


            

Reported by PMD.

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

Line: 161

                @VisibleForTesting
  static class NonSerializableMemoizingSupplier<T extends @Nullable Object> implements Supplier<T> {
    @CheckForNull volatile Supplier<T> delegate;
    volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;

    NonSerializableMemoizingSupplier(Supplier<T> delegate) {

            

Reported by PMD.

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

Line: 164

                  volatile boolean initialized;
    // "value" does not need to be volatile; visibility piggy-backs
    // on volatile read of "initialized".
    @CheckForNull T value;

    NonSerializableMemoizingSupplier(Supplier<T> delegate) {
      this.delegate = checkNotNull(delegate);
    }


            

Reported by PMD.

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

Line: 183

                           * TODO(cpovirk): To avoid having to check for null, replace `delegate` with a singleton
             * `Supplier` that always throws an exception.
             */
            T t = requireNonNull(delegate).get();
            value = t;
            initialized = true;
            // Release the delegate to GC.
            delegate = null;
            return t;

            

Reported by PMD.

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

Line: 187

                          value = t;
            initialized = true;
            // Release the delegate to GC.
            delegate = null;
            return t;
          }
        }
      }
      // This is safe because we checked `initialized.`

            

Reported by PMD.

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

Line: 236

                @SuppressWarnings("GoodTime") // lots of violations
  static class ExpiringMemoizingSupplier<T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    final long durationNanos;
    @CheckForNull transient volatile T value;
    // The special value 0 means "not yet initialized".
    transient volatile long expirationNanos;


            

Reported by PMD.

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

Line: 237

                static class ExpiringMemoizingSupplier<T extends @Nullable Object>
      implements Supplier<T>, Serializable {
    final Supplier<T> delegate;
    final long durationNanos;
    @CheckForNull transient volatile T value;
    // The special value 0 means "not yet initialized".
    transient volatile long expirationNanos;

    ExpiringMemoizingSupplier(Supplier<T> delegate, long duration, TimeUnit unit) {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsValueTester.java
12 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: 38

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

  public void testContainsValueNo() {

            

Reported by PMD.

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

Line: 40

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

  public void testContainsValueNo() {
    assertFalse(multimap().containsValue(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: 43

                  assertTrue(multimap().containsValue(v0()));
  }

  public void testContainsValueNo() {
    assertFalse(multimap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 44

                }

  public void testContainsValueNo() {
    assertFalse(multimap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContainsNullValueYes() {

            

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

                  assertFalse(multimap().containsValue(v3()));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContainsNullValueYes() {
    initMultimapWithNullValue();
    assertTrue(multimap().containsValue(null));
  }

            

Reported by PMD.

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

Line: 51

                @CollectionSize.Require(absent = ZERO)
  public void testContainsNullValueYes() {
    initMultimapWithNullValue();
    assertTrue(multimap().containsValue(null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueNo() {
    assertFalse(multimap().containsValue(null));

            

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

                  assertTrue(multimap().containsValue(null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueNo() {
    assertFalse(multimap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)

            

Reported by PMD.

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

Line: 56

              
  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueNo() {
    assertFalse(multimap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueFails() {
    try {

            

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

                  assertFalse(multimap().containsValue(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueFails() {
    try {
      multimap().containsValue(null);
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {

            

Reported by PMD.

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

Line: 62

                @MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsNullValueFails() {
    try {
      multimap().containsValue(null);
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
      // success
    }
  }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
12 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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapGetTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testGet_yes() {
    assertEquals("get(present) should return the associated value", v0(), get(k0()));
  }

  public void testGet_no() {

            

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

                  assertEquals("get(present) should return the associated value", v0(), get(k0()));
  }

  public void testGet_no() {
    assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedButAllowed() {

            

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

                  assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedButAllowed() {
    assertNull("get(null) should return null", get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)

            

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

                  assertNull("get(null) should return null", get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
  public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }

            

Reported by PMD.

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

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 58

                public void testGet_nullNotContainedAndUnsupported() {
    try {
      assertNull("get(null) should return null or throw", get(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @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: 62

                  }
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testGet_nonNullWhenNullContained() {
    initMapWithNullKey();
    assertNull("get(notPresent) should return null", get(k3()));
  }

            

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

                  assertNull("get(notPresent) should return null", get(k3()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEYS)
  @CollectionSize.Require(absent = ZERO)
  public void testGet_nullContained() {
    initMapWithNullKey();
    assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
  }

            

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

                  assertEquals("get(null) should return the associated value", getValueForNullKey(), get(null));
  }

  public void testGet_wrongType() {
    try {
      assertNull("get(wrongType) should return null or throw", getMap().get(WrongType.VALUE));
    } catch (ClassCastException tolerated) {
    }
  }

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/hash/HashFunctionBenchmark.java
12 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 42

                private static final Random random = new Random(42);

  @Param({"10", "1000", "100000", "1000000"})
  private int size;

  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;


            

Reported by PMD.

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

Line: 44

                @Param({"10", "1000", "100000", "1000000"})
  private int size;

  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 46

              
  @Param HashFunctionEnum hashFunctionEnum;

  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    random.nextBytes(testBytes);

            

Reported by PMD.

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

Line: 48

              
  private byte[] testBytes;

  @BeforeExperiment
  void setUp() {
    testBytes = new byte[size];
    random.nextBytes(testBytes);
  }


            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 59

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 69

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
    }
    return result;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 79

                  HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.hashBytes(testBytes, 1, testBytes.length - 1).asBytes()[0];
    }
    return result;
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'hashFunction' (lines '56'-'62').
Error

Line: 56

              
  @Benchmark
  int hasher(int reps) {
    HashFunction hashFunction = hashFunctionEnum.getHashFunction();
    int result = 37;
    for (int i = 0; i < reps; i++) {
      result ^= hashFunction.newHasher().putBytes(testBytes).hash().asBytes()[0];
    }
    return result;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
12 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: 53

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
  public void testIterator() {
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses iterator()
      iteratorElements.add(element);
    }
    Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);

            

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

                  Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);
  }

  @CollectionFeature.Require(KNOWN_ORDER)
  public void testIterationOrdering() {
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses iterator()
      iteratorElements.add(element);
    }

            

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

                  assertEquals("Different ordered iteration", expected, iteratorElements);
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_nullElement() {
    initCollectionWithNullElement();
    List<E> iteratorElements = new ArrayList<E>();
    for (E element : collection) { // uses 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: 82

                  Helpers.assertEqualIgnoringOrder(asList(createArrayWithNullElement()), iteratorElements);
  }

  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_removeAffectsBackingCollection() {
    int originalSize = collection.size();
    Iterator<E> iterator = collection.iterator();
    Object element = iterator.next();

            

Reported by PMD.

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

Line: 84

              
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testIterator_removeAffectsBackingCollection() {
    int originalSize = collection.size();
    Iterator<E> iterator = collection.iterator();
    Object element = iterator.next();
    // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {

            

Reported by PMD.

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

Line: 91

                  // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {
      Entry<?, ?> entry = (Entry<?, ?>) element;
      element = mapEntry(entry.getKey(), entry.getValue());
    }
    assertTrue(collection.contains(element)); // sanity check
    iterator.remove();
    assertFalse(collection.contains(element));
    assertEquals(originalSize - 1, collection.size());

            

Reported by PMD.

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

Line: 91

                  // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
    if (element instanceof Entry) {
      Entry<?, ?> entry = (Entry<?, ?>) element;
      element = mapEntry(entry.getKey(), entry.getValue());
    }
    assertTrue(collection.contains(element)); // sanity check
    iterator.remove();
    assertFalse(collection.contains(element));
    assertEquals(originalSize - 1, collection.size());

            

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

                  assertEquals(originalSize - 1, collection.size());
  }

  @CollectionFeature.Require({KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})
  public void testIterator_knownOrderRemoveSupported() {
    runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)

            

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

                  runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE)
  public void testIterator_knownOrderRemoveUnsupported() {
    runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)

            

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

                  runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, getOrderedElements());
  }

  @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE)
  public void testIterator_unknownOrderRemoveSupported() {
    runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.UNKNOWN_ORDER, getSampleElements());
  }

  @CollectionFeature.Require(absent = {KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE})

            

Reported by PMD.

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

Line: 33

                private static final String EVENT = "Hello";

  /** The executor we use to fake asynchronicity. */
  private FakeExecutor executor;

  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 35

                /** The executor we use to fake asynchronicity. */
  private FakeExecutor executor;

  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    executor = new FakeExecutor();

            

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

              
  private AsyncEventBus bus;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    executor = new FakeExecutor();
    bus = new AsyncEventBus(executor);
  }

            

Reported by PMD.

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

Line: 44

                  bus = new AsyncEventBus(executor);
  }

  public void testBasicDistribution() {
    StringCatcher catcher = new StringCatcher();
    bus.register(catcher);

    // We post the event, but our Executor will not deliver it until instructed.
    bus.post(EVENT);

            

Reported by PMD.

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

Line: 44

                  bus = new AsyncEventBus(executor);
  }

  public void testBasicDistribution() {
    StringCatcher catcher = new StringCatcher();
    bus.register(catcher);

    // We post the event, but our Executor will not deliver it until instructed.
    bus.post(EVENT);

            

Reported by PMD.

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

Line: 52

                  bus.post(EVENT);

    List<String> events = catcher.getEvents();
    assertTrue("No events should be delivered synchronously.", events.isEmpty());

    // Now we find the task in our Executor and explicitly activate it.
    List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());


            

Reported by PMD.

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

Line: 56

              
    // Now we find the task in our Executor and explicitly activate it.
    List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));

            

Reported by PMD.

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

Line: 58

                  List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }


            

Reported by PMD.

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

Line: 58

                  List<Runnable> tasks = executor.getTasks();
    assertEquals("One event dispatch task should be queued.", 1, tasks.size());

    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }


            

Reported by PMD.

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

Line: 60

              
    tasks.get(0).run();

    assertEquals("One event should be delivered.", 1, events.size());
    assertEquals("Correct string should be delivered.", EVENT, events.get(0));
  }

  /**
   * An {@link Executor} wanna-be that simply records the tasks it's given. Arguably the Worst

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/AbstractBiMapTest.java
12 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: 31

              
  // The next two tests verify that map entries are not accessed after they're
  // removed, since IdentityHashMap throws an exception when that occurs.
  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityKeySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");

            

Reported by PMD.

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

Line: 32

                // The next two tests verify that map entries are not accessed after they're
  // removed, since IdentityHashMap throws an exception when that occurs.
  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityKeySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");
    bimap.put(2, "two");

            

Reported by PMD.

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

Line: 39

                  bimap.put(1, "one");
    bimap.put(2, "two");
    bimap.put(3, "three");
    Iterator<Integer> iterator = bimap.keySet().iterator();
    iterator.next();
    iterator.next();
    iterator.remove();
    iterator.next();
    iterator.remove();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 45

                  iterator.remove();
    iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {

            

Reported by PMD.

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

Line: 46

                  iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                  iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =

            

Reported by PMD.

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

Line: 49

                  assertEquals(1, bimap.inverse().size());
  }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");

            

Reported by PMD.

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

Line: 50

                }

  @SuppressWarnings("IdentityHashMapBoxing") // explicitly testing IdentityHashMap
  public void testIdentityEntrySetIteratorRemove() {
    BiMap<Integer, String> bimap =
        new AbstractBiMap<Integer, String>(
            new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
    bimap.put(1, "one");
    bimap.put(2, "two");

            

Reported by PMD.

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

Line: 57

                  bimap.put(1, "one");
    bimap.put(2, "two");
    bimap.put(3, "three");
    Iterator<Entry<Integer, String>> iterator = bimap.entrySet().iterator();
    iterator.next();
    iterator.next();
    iterator.remove();
    iterator.next();
    iterator.remove();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

                  iterator.remove();
    iterator.next();
    iterator.remove();
    assertEquals(1, bimap.size());
    assertEquals(1, bimap.inverse().size());
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultisetSetCountConditionallyTester.java
12 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 51

                }

  private boolean setCount(E element, int count) {
    return getMultiset().setCount(element, getMultiset().count(element), count);
  }

  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);

            

Reported by PMD.

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

Line: 51

                }

  private boolean setCount(E element, int count) {
    return getMultiset().setCount(element, getMultiset().count(element), count);
  }

  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);

            

Reported by PMD.

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

Line: 56

              
  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);
      fail("calling setCount() with a negative oldCount should throw IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
  }


            

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

              
  // Negative oldCount.

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_negativeOldCount_addSupported() {
    assertSetCountNegativeOldCount();
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)

            

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

                  assertSetCountNegativeOldCount();
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testSetCountConditional_negativeOldCount_addUnsupported() {
    try {
      assertSetCountNegativeOldCount();
    } catch (UnsupportedOperationException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 73

                public void testSetCountConditional_negativeOldCount_addUnsupported() {
    try {
      assertSetCountNegativeOldCount();
    } catch (UnsupportedOperationException tolerated) {
    }
  }

  // Incorrect expected present count.


            

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

              
  // Incorrect expected present count.

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_oldCountTooLarge() {
    assertFalse(
        "setCount() with a too-large oldCount should return false",
        getMultiset().setCount(e0(), 2, 3));
    expectUnchanged();

            

Reported by PMD.

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

Line: 83

                public void testSetCountConditional_oldCountTooLarge() {
    assertFalse(
        "setCount() with a too-large oldCount should return false",
        getMultiset().setCount(e0(), 2, 3));
    expectUnchanged();
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_ADD)

            

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

                  expectUnchanged();
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_oldCountTooSmallZero() {
    assertFalse(
        "setCount() with a too-small oldCount should return false",
        getMultiset().setCount(e0(), 0, 2));

            

Reported by PMD.

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

Line: 92

                public void testSetCountConditional_oldCountTooSmallZero() {
    assertFalse(
        "setCount() with a too-small oldCount should return false",
        getMultiset().setCount(e0(), 0, 2));
    expectUnchanged();
  }

  @CollectionSize.Require(SEVERAL)
  @CollectionFeature.Require(SUPPORTS_ADD)

            

Reported by PMD.