The following issues were found

android/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java
27 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: 34

              public class FileBackedOutputStreamTest extends IoTestCase {


  public void testThreshold() throws Exception {
    testThreshold(0, 100, true, false);
    testThreshold(10, 100, true, false);
    testThreshold(100, 100, true, false);
    testThreshold(1000, 100, true, false);
    testThreshold(0, 100, false, false);

            

Reported by PMD.

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

Line: 45

                  testThreshold(1000, 100, false, false);
  }

  private void testThreshold(
      int fileThreshold, int dataSize, boolean singleByte, boolean resetOnFinalize)
      throws IOException {
    byte[] data = newPreFilledByteArray(dataSize);
    FileBackedOutputStream out = new FileBackedOutputStream(fileThreshold, resetOnFinalize);
    ByteSource source = out.asByteSource();

            

Reported by PMD.

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

Line: 49

                    int fileThreshold, int dataSize, boolean singleByte, boolean resetOnFinalize)
      throws IOException {
    byte[] data = newPreFilledByteArray(dataSize);
    FileBackedOutputStream out = new FileBackedOutputStream(fileThreshold, resetOnFinalize);
    ByteSource source = out.asByteSource();
    int chunk1 = Math.min(dataSize, fileThreshold);
    int chunk2 = dataSize - chunk1;

    // Write just enough to not trip the threshold

            

Reported by PMD.

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

Line: 57

                  // Write just enough to not trip the threshold
    if (chunk1 > 0) {
      write(out, data, 0, chunk1, singleByte);
      assertTrue(ByteSource.wrap(data).slice(0, chunk1).contentEquals(source));
    }
    File file = out.getFile();
    assertNull(file);

    // Write data to go over the threshold

            

Reported by PMD.

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

Line: 57

                  // Write just enough to not trip the threshold
    if (chunk1 > 0) {
      write(out, data, 0, chunk1, singleByte);
      assertTrue(ByteSource.wrap(data).slice(0, chunk1).contentEquals(source));
    }
    File file = out.getFile();
    assertNull(file);

    // Write data to go over the threshold

            

Reported by PMD.

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

Line: 72

                  out.close();

    // Check that source returns the right data
    assertTrue(Arrays.equals(data, source.read()));

    // Make sure that reset deleted the file
    out.reset();
    if (file != null) {
      assertFalse(file.exists());

            

Reported by PMD.

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

Line: 82

                }


  public void testFinalizeDeletesFile() throws Exception {
    byte[] data = newPreFilledByteArray(100);
    FileBackedOutputStream out = new FileBackedOutputStream(0, true);

    write(out, data, 0, 100, true);
    final File file = out.getFile();

            

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

                }


  public void testFinalizeDeletesFile() throws Exception {
    byte[] data = newPreFilledByteArray(100);
    FileBackedOutputStream out = new FileBackedOutputStream(0, true);

    write(out, data, 0, 100, true);
    final File file = out.getFile();

            

Reported by PMD.

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

Line: 84

              
  public void testFinalizeDeletesFile() throws Exception {
    byte[] data = newPreFilledByteArray(100);
    FileBackedOutputStream out = new FileBackedOutputStream(0, true);

    write(out, data, 0, 100, true);
    final File file = out.getFile();
    assertEquals(100, file.length());
    assertTrue(file.exists());

            

Reported by PMD.

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

Line: 88

              
    write(out, data, 0, 100, true);
    final File file = out.getFile();
    assertEquals(100, file.length());
    assertTrue(file.exists());
    out.close();

    // Make sure that finalize deletes the file
    out = null;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java
27 issues
This class has too many methods, consider refactoring it.
Design

Line: 47

              @SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAll_emptyCollection() {
    assertFalse(
        "removeAll(emptyCollection) should return false",
        collection.removeAll(MinimalCollection.of()));

            

Reported by PMD.

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

Line: 48

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAll_emptyCollection() {
    assertFalse(
        "removeAll(emptyCollection) should return false",
        collection.removeAll(MinimalCollection.of()));
    expectUnchanged();

            

Reported by PMD.

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

Line: 56

                  expectUnchanged();
  }

  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testRemoveAll_nonePresent() {
    assertFalse(
        "removeAll(disjointCollection) should return false",
        collection.removeAll(MinimalCollection.of(e3())));
    expectUnchanged();

            

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

                  expectUnchanged();
  }

  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAll_allPresent() {
    assertTrue(
        "removeAll(intersectingCollection) should return true",
        collection.removeAll(MinimalCollection.of(e0())));

            

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

                  expectMissing(e0());
  }

  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAll_somePresent() {
    assertTrue(
        "removeAll(intersectingCollection) should return true",
        collection.removeAll(MinimalCollection.of(e0(), e3())));

            

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

                  expectMissing(e0());
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  @CollectionSize.Require(SEVERAL)
  public void testRemoveAllSomePresentConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      assertTrue(collection.removeAll(MinimalCollection.of(e0(), e3())));

            

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

                }

  /** Trigger the {@code other.size() >= this.size()} case in {@link AbstractSet#removeAll()}. */
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemoveAll_somePresentLargeCollectionToRemove() {
    assertTrue(
        "removeAll(largeIntersectingCollection) should return true",
        collection.removeAll(MinimalCollection.of(e0(), e0(), e0(), e3(), e3(), e3())));

            

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

                  expectMissing(e0());
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  public void testRemoveAll_unsupportedEmptyCollection() {
    try {
      assertFalse(
          "removeAll(emptyCollection) should return false or throw "
              + "UnsupportedOperationException",

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 112

                        "removeAll(emptyCollection) should return false or throw "
              + "UnsupportedOperationException",
          collection.removeAll(MinimalCollection.of()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @CollectionFeature.Require(absent = SUPPORTS_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: 117

                  expectUnchanged();
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  public void testRemoveAll_unsupportedNonePresent() {
    try {
      assertFalse(
          "removeAll(disjointCollection) should return false or throw "
              + "UnsupportedOperationException",

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsKeyTester.java
27 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: 37

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

  public void testContainsKeyNo() {

            

Reported by PMD.

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

Line: 39

              public class MultimapContainsKeyTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(absent = ZERO)
  public void testContainsKeyYes() {
    assertTrue(multimap().containsKey(k0()));
  }

  public void testContainsKeyNo() {
    assertFalse(multimap().containsKey(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: 42

                  assertTrue(multimap().containsKey(k0()));
  }

  public void testContainsKeyNo() {
    assertFalse(multimap().containsKey(k3()));
  }

  public void testContainsKeysFromKeySet() {
    for (K k : multimap().keySet()) {

            

Reported by PMD.

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

Line: 43

                }

  public void testContainsKeyNo() {
    assertFalse(multimap().containsKey(k3()));
  }

  public void testContainsKeysFromKeySet() {
    for (K k : multimap().keySet()) {
      assertTrue(multimap().containsKey(k));

            

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

                  assertFalse(multimap().containsKey(k3()));
  }

  public void testContainsKeysFromKeySet() {
    for (K k : multimap().keySet()) {
      assertTrue(multimap().containsKey(k));
    }
  }


            

Reported by PMD.

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

Line: 47

                }

  public void testContainsKeysFromKeySet() {
    for (K k : multimap().keySet()) {
      assertTrue(multimap().containsKey(k));
    }
  }

  public void testContainsKeyAgreesWithGet() {

            

Reported by PMD.

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

Line: 48

              
  public void testContainsKeysFromKeySet() {
    for (K k : multimap().keySet()) {
      assertTrue(multimap().containsKey(k));
    }
  }

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

            

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

                  }
  }

  public void testContainsKeyAgreesWithGet() {
    for (K k : sampleKeys()) {
      assertEquals(!multimap().get(k).isEmpty(), multimap().containsKey(k));
    }
  }


            

Reported by PMD.

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

Line: 54

              
  public void testContainsKeyAgreesWithGet() {
    for (K k : sampleKeys()) {
      assertEquals(!multimap().get(k).isEmpty(), multimap().containsKey(k));
    }
  }

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

            

Reported by PMD.

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

Line: 54

              
  public void testContainsKeyAgreesWithGet() {
    for (K k : sampleKeys()) {
      assertEquals(!multimap().get(k).isEmpty(), multimap().containsKey(k));
    }
  }

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

            

Reported by PMD.

guava/src/com/google/common/collect/ImmutableMultiset.java
27 issues
Avoid reassigning parameters such as 'offset'
Design

Line: 328

              
  @GwtIncompatible // not present in emulated superclass
  @Override
  int copyIntoArray(Object[] dst, int offset) {
    for (Multiset.Entry<E> entry : entrySet()) {
      Arrays.fill(dst, offset, offset + entry.getCount(), entry.getElement());
      offset += entry.getCount();
    }
    return offset;

            

Reported by PMD.

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

Line: 60

              @SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializationDependencies<E>
    implements Multiset<E> {

  /**
   * Returns a {@code Collector} that accumulates the input elements into a new {@code
   * ImmutableMultiset}. Elements iterate in order by the <i>first</i> appearance of that element in
   * encounter order.

            

Reported by PMD.

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

Line: 186

                  if (elements instanceof ImmutableMultiset) {
      @SuppressWarnings("unchecked") // all supported methods are covariant
      ImmutableMultiset<E> result = (ImmutableMultiset<E>) elements;
      if (!result.isPartialView()) {
        return result;
      }
    }

    Multiset<? extends E> multiset =

            

Reported by PMD.

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

Line: 196

                          ? Multisets.cast(elements)
            : LinkedHashMultiset.create(elements);

    return copyFromEntries(multiset.entrySet());
  }

  /**
   * Returns an immutable multiset containing the given elements, in the "grouped iteration order"
   * described in the class documentation.

            

Reported by PMD.

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

Line: 208

                public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> elements) {
    Multiset<E> multiset = LinkedHashMultiset.create();
    Iterators.addAll(multiset, elements);
    return copyFromEntries(multiset.entrySet());
  }

  private static <E> ImmutableMultiset<E> copyFromElements(E... elements) {
    Multiset<E> multiset = LinkedHashMultiset.create();
    Collections.addAll(multiset, elements);

            

Reported by PMD.

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

Line: 214

                private static <E> ImmutableMultiset<E> copyFromElements(E... elements) {
    Multiset<E> multiset = LinkedHashMultiset.create();
    Collections.addAll(multiset, elements);
    return copyFromEntries(multiset.entrySet());
  }

  static <E> ImmutableMultiset<E> copyFromEntries(
      Collection<? extends Entry<? extends E>> entries) {
    if (entries.isEmpty()) {

            

Reported by PMD.

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

Line: 230

              
  @Override
  public UnmodifiableIterator<E> iterator() {
    final Iterator<Entry<E>> entryIterator = entrySet().iterator();
    return new UnmodifiableIterator<E>() {
      int remaining;
      @CheckForNull E element;

      @Override

            

Reported by PMD.

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

Line: 244

                    public E next() {
        if (remaining <= 0) {
          Entry<E> entry = entryIterator.next();
          element = entry.getElement();
          remaining = entry.getCount();
        }
        remaining--;
        /*
         * requireNonNull is safe because `remaining` starts at 0, forcing us to initialize

            

Reported by PMD.

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

Line: 245

                      if (remaining <= 0) {
          Entry<E> entry = entryIterator.next();
          element = entry.getElement();
          remaining = entry.getCount();
        }
        remaining--;
        /*
         * requireNonNull is safe because `remaining` starts at 0, forcing us to initialize
         * `element` above. After that, we never clear it.

            

Reported by PMD.

Field asList has the same name as a method
Error

Line: 257

                  };
  }

  @LazyInit @CheckForNull private transient ImmutableList<E> asList;

  @Override
  public ImmutableList<E> asList() {
    ImmutableList<E> result = asList;
    return (result == null) ? asList = super.asList() : result;

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/FuturesGetChecked.java
27 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 62

                  try {
      return future.get();
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 66

                    throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }
  }

  /** Implementation of {@link Futures#getChecked(Future, Class, long, TimeUnit)}. */
  @CanIgnoreReturnValue

            

Reported by PMD.

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

Line: 76

                static <V extends @Nullable Object, X extends Exception> V getChecked(
      Future<V> future, Class<X> exceptionClass, long timeout, TimeUnit unit) throws X {
    // TODO(cpovirk): benchmark a version of this method that accepts a GetCheckedTypeValidator
    bestGetCheckedTypeValidator().validateClass(exceptionClass);
    try {
      return future.get(timeout, unit);
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);

            

Reported by PMD.

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

Line: 80

                  try {
      return future.get(timeout, unit);
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);
    } catch (TimeoutException e) {
      throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 86

                    throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }
  }

  @VisibleForTesting
  interface GetCheckedTypeValidator {

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 117

                 * <p>Uses reflection to gracefully fall back to when certain implementations aren't available.
   */
  @VisibleForTesting
  static class GetCheckedTypeValidatorHolder {
    static final String CLASS_VALUE_VALIDATOR_NAME =
        GetCheckedTypeValidatorHolder.class.getName() + "$ClassValueValidator";

    static final GetCheckedTypeValidator BEST_VALIDATOR = getBestValidator();


            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 179

                       * Ideally we'd have a real eviction policy, but until we see a problem in practice, I hope
         * that this will suffice. I have not even benchmarked with different size limits.
         */
        if (validClasses.size() > 1000) {
          validClasses.clear();
        }

        validClasses.add(new WeakReference<Class<? extends Exception>>(exceptionClass));
      }

            

Reported by PMD.

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

Line: 194

                  static GetCheckedTypeValidator getBestValidator() {
      try {
        Class<? extends Enum> theClass =
            Class.forName(CLASS_VALUE_VALIDATOR_NAME).asSubclass(Enum.class);
        return (GetCheckedTypeValidator) theClass.getEnumConstants()[0];
      } catch (Throwable t) { // ensure we really catch *everything*
        return weakSetValidator();
      }
    }

            

Reported by PMD.

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

Line: 195

                    try {
        Class<? extends Enum> theClass =
            Class.forName(CLASS_VALUE_VALIDATOR_NAME).asSubclass(Enum.class);
        return (GetCheckedTypeValidator) theClass.getEnumConstants()[0];
      } catch (Throwable t) { // ensure we really catch *everything*
        return weakSetValidator();
      }
    }
  }

            

Reported by PMD.

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

Line: 196

                      Class<? extends Enum> theClass =
            Class.forName(CLASS_VALUE_VALIDATOR_NAME).asSubclass(Enum.class);
        return (GetCheckedTypeValidator) theClass.getEnumConstants()[0];
      } catch (Throwable t) { // ensure we really catch *everything*
        return weakSetValidator();
      }
    }
  }


            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/WrappingScheduledExecutorServiceTest.java
27 issues
JUnit tests should include assert() or fail()
Design

Line: 45

                      public void run() {}
      };

  public void testSchedule() {
    MockExecutor mock = new MockExecutor();
    TestExecutor testExecutor = new TestExecutor(mock);

    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError = testExecutor.schedule(DO_NOTHING, 10, TimeUnit.MINUTES);

            

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

                      public void run() {}
      };

  public void testSchedule() {
    MockExecutor mock = new MockExecutor();
    TestExecutor testExecutor = new TestExecutor(mock);

    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError = testExecutor.schedule(DO_NOTHING, 10, TimeUnit.MINUTES);

            

Reported by PMD.

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

Line: 49

                  MockExecutor mock = new MockExecutor();
    TestExecutor testExecutor = new TestExecutor(mock);

    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError = testExecutor.schedule(DO_NOTHING, 10, TimeUnit.MINUTES);
    mock.assertLastMethodCalled("scheduleRunnable", 10, TimeUnit.MINUTES);

    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError1 =

            

Reported by PMD.

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

Line: 59

                  mock.assertLastMethodCalled("scheduleCallable", 5, TimeUnit.SECONDS);
  }

  public void testSchedule_repeating() {
    MockExecutor mock = new MockExecutor();
    TestExecutor testExecutor = new TestExecutor(mock);
    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError =
        testExecutor.scheduleWithFixedDelay(DO_NOTHING, 100, 10, TimeUnit.MINUTES);

            

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

                  mock.assertLastMethodCalled("scheduleCallable", 5, TimeUnit.SECONDS);
  }

  public void testSchedule_repeating() {
    MockExecutor mock = new MockExecutor();
    TestExecutor testExecutor = new TestExecutor(mock);
    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
    Future<?> possiblyIgnoredError =
        testExecutor.scheduleWithFixedDelay(DO_NOTHING, 100, 10, TimeUnit.MINUTES);

            

Reported by PMD.

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

Line: 74

                }

  private static final class WrappedCallable<T> implements Callable<T> {
    private final Callable<T> delegate;

    public WrappedCallable(Callable<T> delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

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

Line: 87

                }

  private static final class WrappedRunnable implements Runnable {
    private final Runnable delegate;

    public WrappedRunnable(Runnable delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

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

Line: 115

                  }
  }

  private static final class MockExecutor implements ScheduledExecutorService {
    String lastMethodCalled = "";
    long lastInitialDelay;
    long lastDelay;
    TimeUnit lastUnit;


            

Reported by PMD.

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

Line: 116

                }

  private static final class MockExecutor implements ScheduledExecutorService {
    String lastMethodCalled = "";
    long lastInitialDelay;
    long lastDelay;
    TimeUnit lastUnit;

    void assertLastMethodCalled(String method, long delay, TimeUnit unit) {

            

Reported by PMD.

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

Line: 117

              
  private static final class MockExecutor implements ScheduledExecutorService {
    String lastMethodCalled = "";
    long lastInitialDelay;
    long lastDelay;
    TimeUnit lastUnit;

    void assertLastMethodCalled(String method, long delay, TimeUnit unit) {
      assertEquals(method, lastMethodCalled);

            

Reported by PMD.

guava/src/com/google/common/util/concurrent/AggregateFuture.java
27 issues
This class has too many methods, consider refactoring it.
Design

Line: 46

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class AggregateFuture<InputT extends @Nullable Object, OutputT extends @Nullable Object>
    extends AggregateFutureState<OutputT> {
  private static final Logger logger = Logger.getLogger(AggregateFuture.class.getName());

  /**
   * The input futures. After {@link #init}, this field is read only by {@link #afterDone()} (to
   * propagate cancellation) and {@link #toString()}. To access the futures' <i>values</i>, {@code

            

Reported by PMD.

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

Line: 59

                 * In certain circumstances, this field might theoretically not be visible to an afterDone() call
   * triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
   */
  @CheckForNull private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures;

  private final boolean allMustSucceed;
  private final boolean collectsValues;

  AggregateFuture(

            

Reported by PMD.

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

Line: 61

                 */
  @CheckForNull private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures;

  private final boolean allMustSucceed;
  private final boolean collectsValues;

  AggregateFuture(
      ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
      boolean allMustSucceed,

            

Reported by PMD.

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

Line: 62

                @CheckForNull private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures;

  private final boolean allMustSucceed;
  private final boolean collectsValues;

  AggregateFuture(
      ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
      boolean allMustSucceed,
      boolean collectsValues) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 141

                    for (final ListenableFuture<? extends InputT> future : futures) {
        final int index = i++;
        future.addListener(
            new Runnable() {
              @Override
              public void run() {
                try {
                  if (future.isCancelled()) {
                    // Clear futures prior to cancelling children. This sets our own state but lets

            

Reported by PMD.

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

Line: 148

                                if (future.isCancelled()) {
                    // Clear futures prior to cancelling children. This sets our own state but lets
                    // the input futures keep running, as some of them may be used elsewhere.
                    futures = null;
                    cancel(false);
                  } else {
                    collectValueFromNonCancelledFuture(index, future);
                  }
                } finally {

            

Reported by PMD.

Avoid unused local variables such as 'unused'.
Design

Line: 256

                     * TODO(cpovirk): Think about whether we could/should use Verify to check the return value of
       * addCausalChain.
       */
      boolean unused = addCausalChain(seen, requireNonNull(tryInternalFastPathGetFailure()));
    }
  }

  /**
   * Collects the result (success or failure) of one input future. The input must not have been

            

Reported by PMD.

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

Line: 270

                    collectOneValue(index, getDone(future));
    } catch (ExecutionException e) {
      handleException(e.getCause());
    } catch (Throwable t) {
      handleException(t);
    }
  }

  private void decrementCountAndMaybeComplete(

            

Reported by PMD.

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

Line: 331

                   * either case, no one needs to read `futures` for cancellation purposes later. (And
     * cancellation purposes are the main reason to access `futures`, as discussed in its docs.)
     */
    this.futures = null;
  }

  enum ReleaseResourcesReason {
    OUTPUT_FUTURE_DONE,
    ALL_INPUT_FUTURES_PROCESSED,

            

Reported by PMD.

Found 'DU'-anomaly for variable 'wasInterrupted' (lines '82'-'91').
Error

Line: 82

                  releaseResources(OUTPUT_FUTURE_DONE); // nulls out `futures`

    if (isCancelled() & localFutures != null) {
      boolean wasInterrupted = wasInterrupted();
      for (Future<?> future : localFutures) {
        future.cancel(wasInterrupted);
      }
    }
    /*

            

Reported by PMD.

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

Line: 40

              @ElementTypesAreNonnullByDefault
abstract class AbstractTable<
        R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object>
    implements Table<R, C, V> {

  @Override
  public boolean containsRow(@CheckForNull Object rowKey) {
    return Maps.safeContainsKey(rowMap(), rowKey);
  }

            

Reported by PMD.

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

Line: 54

              
  @Override
  public Set<R> rowKeySet() {
    return rowMap().keySet();
  }

  @Override
  public Set<C> columnKeySet() {
    return columnMap().keySet();

            

Reported by PMD.

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

Line: 59

              
  @Override
  public Set<C> columnKeySet() {
    return columnMap().keySet();
  }

  @Override
  public boolean containsValue(@CheckForNull Object value) {
    for (Map<C, V> row : rowMap().values()) {

            

Reported by PMD.

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

Line: 64

              
  @Override
  public boolean containsValue(@CheckForNull Object value) {
    for (Map<C, V> row : rowMap().values()) {
      if (row.containsValue(value)) {
        return true;
      }
    }
    return false;

            

Reported by PMD.

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

Line: 92

              
  @Override
  public void clear() {
    Iterators.clear(cellSet().iterator());
  }

  @CanIgnoreReturnValue
  @Override
  @CheckForNull

            

Reported by PMD.

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

Line: 108

                @CheckForNull
  public V put(
      @ParametricNullness R rowKey, @ParametricNullness C columnKey, @ParametricNullness V value) {
    return row(rowKey).put(columnKey, value);
  }

  @Override
  public void putAll(Table<? extends R, ? extends C, ? extends V> table) {
    for (Table.Cell<? extends R, ? extends C, ? extends V> cell : table.cellSet()) {

            

Reported by PMD.

Field cellSet has the same name as a method
Error

Line: 118

                  }
  }

  @LazyInit @CheckForNull private transient Set<Cell<R, C, V>> cellSet;

  @Override
  public Set<Cell<R, C, V>> cellSet() {
    Set<Cell<R, C, V>> result = cellSet;
    return (result == null) ? cellSet = createCellSet() : result;

            

Reported by PMD.

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

Line: 140

                  public boolean contains(@CheckForNull Object o) {
      if (o instanceof Cell) {
        Cell<?, ?, ?> cell = (Cell<?, ?, ?>) o;
        Map<C, V> row = Maps.safeGet(rowMap(), cell.getRowKey());
        return row != null
            && Collections2.safeContains(
                row.entrySet(), Maps.immutableEntry(cell.getColumnKey(), cell.getValue()));
      }
      return false;

            

Reported by PMD.

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

Line: 143

                      Map<C, V> row = Maps.safeGet(rowMap(), cell.getRowKey());
        return row != null
            && Collections2.safeContains(
                row.entrySet(), Maps.immutableEntry(cell.getColumnKey(), cell.getValue()));
      }
      return false;
    }

    @Override

            

Reported by PMD.

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

Line: 143

                      Map<C, V> row = Maps.safeGet(rowMap(), cell.getRowKey());
        return row != null
            && Collections2.safeContains(
                row.entrySet(), Maps.immutableEntry(cell.getColumnKey(), cell.getValue()));
      }
      return false;
    }

    @Override

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/AtomicsTest.java
27 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: 32

              
  private static final Object OBJECT = new Object();

  public void testNewReference() throws Exception {
    assertEquals(null, Atomics.newReference().get());
  }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());

            

Reported by PMD.

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

Line: 33

                private static final Object OBJECT = new Object();

  public void testNewReference() throws Exception {
    assertEquals(null, Atomics.newReference().get());
  }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                private static final Object OBJECT = new Object();

  public void testNewReference() throws Exception {
    assertEquals(null, Atomics.newReference().get());
  }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());

            

Reported by PMD.

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

Line: 36

                  assertEquals(null, Atomics.newReference().get());
  }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {

            

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(null, Atomics.newReference().get());
  }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 37

                }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {
    int length = 42;

            

Reported by PMD.

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

Line: 37

                }

  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {
    int length = 42;

            

Reported by PMD.

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

Line: 38

              
  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {
    int length = 42;
    AtomicReferenceArray<String> refArray = Atomics.newReferenceArray(length);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

              
  public void testNewReference_withInitialValue() throws Exception {
    assertEquals(null, Atomics.newReference(null).get());
    assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {
    int length = 42;
    AtomicReferenceArray<String> refArray = Atomics.newReferenceArray(length);

            

Reported by PMD.

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

Line: 41

                  assertEquals(OBJECT, Atomics.newReference(OBJECT).get());
  }

  public void testNewReferenceArray_withLength() throws Exception {
    int length = 42;
    AtomicReferenceArray<String> refArray = Atomics.newReferenceArray(length);
    for (int i = 0; i < length; ++i) {
      assertEquals(null, refArray.get(i));
    }

            

Reported by PMD.

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

Line: 31

               * @author Joshua O'Madadhain
 */
@ElementTypesAreNonnullByDefault
abstract class ForwardingNetwork<N, E> extends AbstractNetwork<N, E> {

  abstract Network<N, E> delegate();

  @Override
  public Set<N> nodes() {

            

Reported by PMD.

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

Line: 37

              
  @Override
  public Set<N> nodes() {
    return delegate().nodes();
  }

  @Override
  public Set<E> edges() {
    return delegate().edges();

            

Reported by PMD.

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

Line: 42

              
  @Override
  public Set<E> edges() {
    return delegate().edges();
  }

  @Override
  public boolean isDirected() {
    return delegate().isDirected();

            

Reported by PMD.

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

Line: 47

              
  @Override
  public boolean isDirected() {
    return delegate().isDirected();
  }

  @Override
  public boolean allowsParallelEdges() {
    return delegate().allowsParallelEdges();

            

Reported by PMD.

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

Line: 52

              
  @Override
  public boolean allowsParallelEdges() {
    return delegate().allowsParallelEdges();
  }

  @Override
  public boolean allowsSelfLoops() {
    return delegate().allowsSelfLoops();

            

Reported by PMD.

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

Line: 57

              
  @Override
  public boolean allowsSelfLoops() {
    return delegate().allowsSelfLoops();
  }

  @Override
  public ElementOrder<N> nodeOrder() {
    return delegate().nodeOrder();

            

Reported by PMD.

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

Line: 62

              
  @Override
  public ElementOrder<N> nodeOrder() {
    return delegate().nodeOrder();
  }

  @Override
  public ElementOrder<E> edgeOrder() {
    return delegate().edgeOrder();

            

Reported by PMD.

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

Line: 67

              
  @Override
  public ElementOrder<E> edgeOrder() {
    return delegate().edgeOrder();
  }

  @Override
  public Set<N> adjacentNodes(N node) {
    return delegate().adjacentNodes(node);

            

Reported by PMD.

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

Line: 72

              
  @Override
  public Set<N> adjacentNodes(N node) {
    return delegate().adjacentNodes(node);
  }

  @Override
  public Set<N> predecessors(N node) {
    return delegate().predecessors(node);

            

Reported by PMD.

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

Line: 77

              
  @Override
  public Set<N> predecessors(N node) {
    return delegate().predecessors(node);
  }

  @Override
  public Set<N> successors(N node) {
    return delegate().successors(node);

            

Reported by PMD.