The following issues were found

guava-tests/test/com/google/common/collect/ImmutableRangeMapTest.java
95 issues
This class has too many methods, consider refactoring it.
Design

Line: 32

               * @author Louis Wasserman
 */
@GwtIncompatible // NavigableMap
public class ImmutableRangeMapTest extends TestCase {
  private static final ImmutableList<Range<Integer>> RANGES;
  private static final int MIN_BOUND = 0;
  private static final int MAX_BOUND = 10;

  static {

            

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

                  RANGES = builder.build();
  }

  public void testBuilderRejectsEmptyRanges() {
    for (int i = MIN_BOUND; i <= MAX_BOUND; i++) {
      ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
      try {
        builder.put(Range.closedOpen(i, i), 1);
        fail("Expected IllegalArgumentException");

            

Reported by PMD.

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

Line: 71

                    ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
      try {
        builder.put(Range.closedOpen(i, i), 1);
        fail("Expected IllegalArgumentException");
      } catch (IllegalArgumentException expected) {
        // success
      }
      try {
        builder.put(Range.openClosed(i, i), 1);

            

Reported by PMD.

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

Line: 77

                    }
      try {
        builder.put(Range.openClosed(i, i), 1);
        fail("Expected 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: 83

                  }
  }

  public void testOverlapRejection() {
    for (Range<Integer> range1 : RANGES) {
      for (Range<Integer> range2 : RANGES) {
        boolean expectRejection =
            range1.isConnected(range2) && !range1.intersection(range2).isEmpty();
        ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();

            

Reported by PMD.

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

Line: 83

                  }
  }

  public void testOverlapRejection() {
    for (Range<Integer> range1 : RANGES) {
      for (Range<Integer> range2 : RANGES) {
        boolean expectRejection =
            range1.isConnected(range2) && !range1.intersection(range2).isEmpty();
        ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();

            

Reported by PMD.

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

Line: 87

                  for (Range<Integer> range1 : RANGES) {
      for (Range<Integer> range2 : RANGES) {
        boolean expectRejection =
            range1.isConnected(range2) && !range1.intersection(range2).isEmpty();
        ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
        builder.put(range1, 1).put(range2, 2);
        try {
          ImmutableRangeMap<Integer, Integer> unused = builder.build();
          assertFalse(expectRejection);

            

Reported by PMD.

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

Line: 89

                      boolean expectRejection =
            range1.isConnected(range2) && !range1.intersection(range2).isEmpty();
        ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
        builder.put(range1, 1).put(range2, 2);
        try {
          ImmutableRangeMap<Integer, Integer> unused = builder.build();
          assertFalse(expectRejection);
        } catch (IllegalArgumentException e) {
          assertTrue(expectRejection);

            

Reported by PMD.

Avoid unused local variables such as 'unused'.
Design

Line: 91

                      ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
        builder.put(range1, 1).put(range2, 2);
        try {
          ImmutableRangeMap<Integer, Integer> unused = builder.build();
          assertFalse(expectRejection);
        } catch (IllegalArgumentException e) {
          assertTrue(expectRejection);
        }
      }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 92

                      builder.put(range1, 1).put(range2, 2);
        try {
          ImmutableRangeMap<Integer, Integer> unused = builder.build();
          assertFalse(expectRejection);
        } catch (IllegalArgumentException e) {
          assertTrue(expectRejection);
        }
      }
    }

            

Reported by PMD.

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

Line: 48

               * @author Steve McKay
 */
@GwtCompatible(emulated = true)
public class EnumsTest extends TestCase {

  private enum TestEnum {
    CHEETO,
    HONDA,
    POODLE,

            

Reported by PMD.

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

Line: 58

              
  private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();

            

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

              
  private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();

            

Reported by PMD.

The String literal 'CHEETO' appears 5 times in this file; the first occurrence is on line 59
Error

Line: 59

                private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();

            

Reported by PMD.

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

Line: 59

                private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();

            

Reported by PMD.

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

Line: 60

              
  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

            

Reported by PMD.

The String literal 'HONDA' appears 5 times in this file; the first occurrence is on line 60
Error

Line: 60

              
  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

            

Reported by PMD.

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

Line: 61

                public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();


            

Reported by PMD.

The String literal 'POODLE' appears 5 times in this file; the first occurrence is on line 61
Error

Line: 61

                public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();


            

Reported by PMD.

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

Line: 63

                  assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);

            

Reported by PMD.

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

Line: 48

               * @author Steve McKay
 */
@GwtCompatible(emulated = true)
public class EnumsTest extends TestCase {

  private enum TestEnum {
    CHEETO,
    HONDA,
    POODLE,

            

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

              
  private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();

            

Reported by PMD.

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

Line: 58

              
  private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();

            

Reported by PMD.

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

Line: 59

                private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();

            

Reported by PMD.

The String literal 'CHEETO' appears 5 times in this file; the first occurrence is on line 59
Error

Line: 59

                private enum OtherEnum {}

  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();

            

Reported by PMD.

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

Line: 60

              
  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

            

Reported by PMD.

The String literal 'HONDA' appears 5 times in this file; the first occurrence is on line 60
Error

Line: 60

              
  public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

            

Reported by PMD.

The String literal 'POODLE' appears 5 times in this file; the first occurrence is on line 61
Error

Line: 61

                public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();


            

Reported by PMD.

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

Line: 61

                public void testGetIfPresent() {
    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();


            

Reported by PMD.

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

Line: 63

                  assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE);

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent();
    assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent();

    assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO);
    assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA);

            

Reported by PMD.

android/guava/src/com/google/common/collect/TreeMultiset.java
91 issues
Possible God Class (WMC=78, ATFD=67, TCC=19.697%)
Design

Line: 61

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class TreeMultiset<E extends @Nullable Object> extends AbstractSortedMultiset<E>
    implements Serializable {

  /**
   * Creates a new, empty multiset, sorted according to the elements' natural order. All elements
   * inserted into the multiset must implement the {@code Comparable} interface. Furthermore, all

            

Reported by PMD.

Avoid really long classes.
Design

Line: 61

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class TreeMultiset<E extends @Nullable Object> extends AbstractSortedMultiset<E>
    implements Serializable {

  /**
   * Creates a new, empty multiset, sorted according to the elements' natural order. All elements
   * inserted into the multiset must implement the {@code Comparable} interface. Furthermore, all

            

Reported by PMD.

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

Line: 62

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class TreeMultiset<E extends @Nullable Object> extends AbstractSortedMultiset<E>
    implements Serializable {

  /**
   * Creates a new, empty multiset, sorted according to the elements' natural order. All elements
   * inserted into the multiset must implement the {@code Comparable} interface. Furthermore, all
   * such elements must be <i>mutually comparable</i>: {@code e1.compareTo(e2)} must not throw a

            

Reported by PMD.

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

Line: 91

                 * @param comparator the comparator that will be used to sort this multiset. A null value
   *     indicates that the elements' <i>natural ordering</i> should be used.
   */
  @SuppressWarnings("unchecked")
  public static <E extends @Nullable Object> TreeMultiset<E> create(
      @CheckForNull Comparator<? super E> comparator) {
    return (comparator == null)
        ? new TreeMultiset<E>((Comparator) Ordering.natural())
        : new TreeMultiset<E>(comparator);

            

Reported by PMD.

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

Line: 181

                  }
    // The cast is safe because we call this method only if hasLowerBound().
    int cmp =
        comparator()
            .compare(uncheckedCastNullableTToT(range.getLowerEndpoint()), node.getElement());
    if (cmp < 0) {
      return aggregateBelowRange(aggr, node.left);
    } else if (cmp == 0) {
      switch (range.getLowerBoundType()) {

            

Reported by PMD.

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

Line: 207

                  }
    // The cast is safe because we call this method only if hasUpperBound().
    int cmp =
        comparator()
            .compare(uncheckedCastNullableTToT(range.getUpperEndpoint()), node.getElement());
    if (cmp > 0) {
      return aggregateAboveRange(aggr, node.right);
    } else if (cmp == 0) {
      switch (range.getUpperBoundType()) {

            

Reported by PMD.

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

Line: 250

                    if (!range.contains(e) || root == null) {
        return 0;
      }
      return root.count(comparator(), e);
    } catch (ClassCastException | NullPointerException e) {
      return 0;
    }
  }


            

Reported by PMD.

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

Line: 251

                      return 0;
      }
      return root.count(comparator(), e);
    } catch (ClassCastException | NullPointerException e) {
      return 0;
    }
  }

  @CanIgnoreReturnValue

            

Reported by PMD.

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

Line: 251

                      return 0;
      }
      return root.count(comparator(), e);
    } catch (ClassCastException | NullPointerException e) {
      return 0;
    }
  }

  @CanIgnoreReturnValue

            

Reported by PMD.

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

Line: 266

                  checkArgument(range.contains(element));
    AvlNode<E> root = rootReference.get();
    if (root == null) {
      comparator().compare(element, element);
      AvlNode<E> newRoot = new AvlNode<E>(element, occurrences);
      successor(header, newRoot, header);
      rootReference.checkAndSet(root, newRoot);
      return 0;
    }

            

Reported by PMD.

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

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.collect.CollectPreconditions.checkRemove;
import static com.google.common.collect.CompactHashing.UNSET;
import static com.google.common.collect.Hashing.smearedHash;
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;

            

Reported by PMD.

The class 'CompactHashMap' has a total cyclomatic complexity of 107 (highest 10).
Design

Line: 80

               */
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements Serializable {
  /*
   * TODO: Make this a drop-in replacement for j.u. versions, actually drop them in, and test the
   * world. Figure out what sort of space-time tradeoff we're actually going to get here with the
   * *Map variants. This class is particularly hard to benchmark, because the benefit is not only in

            

Reported by PMD.

Avoid really long classes.
Design

Line: 80

               */
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements Serializable {
  /*
   * TODO: Make this a drop-in replacement for j.u. versions, actually drop them in, and test the
   * world. Figure out what sort of space-time tradeoff we're actually going to get here with the
   * *Map variants. This class is particularly hard to benchmark, because the benefit is not only in

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 80

               */
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements Serializable {
  /*
   * TODO: Make this a drop-in replacement for j.u. versions, actually drop them in, and test the
   * world. Figure out what sort of space-time tradeoff we're actually going to get here with the
   * *Map variants. This class is particularly hard to benchmark, because the benefit is not only in

            

Reported by PMD.

Possible God Class (WMC=107, ATFD=20, TCC=4.790%)
Design

Line: 80

               */
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements Serializable {
  /*
   * TODO: Make this a drop-in replacement for j.u. versions, actually drop them in, and test the
   * world. Figure out what sort of space-time tradeoff we're actually going to get here with the
   * *Map variants. This class is particularly hard to benchmark, because the benefit is not only in

            

Reported by PMD.

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

Line: 81

              @GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements Serializable {
  /*
   * TODO: Make this a drop-in replacement for j.u. versions, actually drop them in, and test the
   * world. Figure out what sort of space-time tradeoff we're actually going to get here with the
   * *Map variants. This class is particularly hard to benchmark, because the benefit is not only in
   * less allocation, but also having the GC do less work to scan the heap because of fewer

            

Reported by PMD.

Field values has the same name as a method
Error

Line: 214

                 * The values of the entries in the map, in the range of [0, size()). The values in [size(),
   * values.length) are all {@code null}.
   */
  @VisibleForTesting @CheckForNull transient @Nullable Object[] values;

  /**
   * Keeps track of metadata like the number of hash table bits and modifications of this data
   * structure (to make it possible to throw ConcurrentModificationException in the iterator). Note
   * that we choose not to make this volatile, so we do less of a "best effort" to track such

            

Reported by PMD.

Field size has the same name as a method
Error

Line: 231

                private transient int metadata;

  /** The number of elements contained in the set. */
  private transient int size;

  /** Constructs a new empty instance of {@code CompactHashMap}. */
  CompactHashMap() {
    init(CompactHashing.DEFAULT_SIZE);
  }

            

Reported by PMD.

The String literal 'unchecked' appears 6 times in this file; the first occurrence is on line 278
Error

Line: 278

                  return expectedSize;
  }

  @SuppressWarnings("unchecked")
  @VisibleForTesting
  @CheckForNull
  Map<K, V> delegateOrNull() {
    if (table instanceof Map) {
      return (Map<K, V>) table;

            

Reported by PMD.

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

Line: 300

                    newDelegate.put(key(i), value(i));
    }
    this.table = newDelegate;
    this.entries = null;
    this.keys = null;
    this.values = null;
    incrementModCount();
    return newDelegate;
  }

            

Reported by PMD.

guava-tests/test/com/google/common/collect/SynchronizedNavigableMapTest.java
90 issues
Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 263

                  suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {
                  private final Object mutex = new Integer(1);

                  @Override
                  protected SortedMap<String, String> create(Entry<String, String>[] entries) {
                    NavigableMap<String, String> innermost = new SafeTreeMap<>();
                    for (Entry<String, String> entry : entries) {

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import com.google.common.collect.Synchronized.SynchronizedNavigableMap;
import com.google.common.collect.Synchronized.SynchronizedNavigableSet;
import com.google.common.collect.Synchronized.SynchronizedSortedMap;
import com.google.common.collect.testing.NavigableMapTestSuiteBuilder;

            

Reported by PMD.

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

Line: 42

               *
 * @author Louis Wasserman
 */
public class SynchronizedNavigableMapTest extends SynchronizedMapTest {
  @Override
  protected <K, V> NavigableMap<K, V> create() {
    @SuppressWarnings("unchecked")
    NavigableMap<K, V> innermost =
        new SafeTreeMap<>((Comparator<? super K>) Ordering.natural().nullsFirst());

            

Reported by PMD.

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

Line: 47

                protected <K, V> NavigableMap<K, V> create() {
    @SuppressWarnings("unchecked")
    NavigableMap<K, V> innermost =
        new SafeTreeMap<>((Comparator<? super K>) Ordering.natural().nullsFirst());
    TestMap<K, V> inner = new TestMap<>(innermost, mutex);
    NavigableMap<K, V> outer = Synchronized.navigableMap(inner, mutex);
    return outer;
  }


            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 54

                }

  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;

            

Reported by PMD.

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

Line: 54

                }

  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;

            

Reported by PMD.

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

Line: 55

              
  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;
    }

            

Reported by PMD.

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

Line: 101

                }

  static class TestMap<K, V> extends SynchronizedMapTest.TestMap<K, V>
      implements NavigableMap<K, V> {

    public TestMap(NavigableMap<K, V> delegate, Object mutex) {
      super(delegate, mutex);
    }


            

Reported by PMD.

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

Line: 115

                  @Override
    public Entry<K, V> ceilingEntry(K key) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate().ceilingEntry(key);
    }

    @Override
    public K ceilingKey(K key) {
      assertTrue(Thread.holdsLock(mutex));

            

Reported by PMD.

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

Line: 121

                  @Override
    public K ceilingKey(K key) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate().ceilingKey(key);
    }

    @Override
    public NavigableSet<K> descendingKeySet() {
      assertTrue(Thread.holdsLock(mutex));

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/SynchronizedNavigableMapTest.java
90 issues
Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 263

                  suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {
                  private final Object mutex = new Integer(1);

                  @Override
                  protected SortedMap<String, String> create(Entry<String, String>[] entries) {
                    NavigableMap<String, String> innermost = new SafeTreeMap<>();
                    for (Entry<String, String> entry : entries) {

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import com.google.common.collect.Synchronized.SynchronizedNavigableMap;
import com.google.common.collect.Synchronized.SynchronizedNavigableSet;
import com.google.common.collect.Synchronized.SynchronizedSortedMap;
import com.google.common.collect.testing.NavigableMapTestSuiteBuilder;

            

Reported by PMD.

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

Line: 42

               *
 * @author Louis Wasserman
 */
public class SynchronizedNavigableMapTest extends SynchronizedMapTest {
  @Override
  protected <K, V> NavigableMap<K, V> create() {
    @SuppressWarnings("unchecked")
    NavigableMap<K, V> innermost =
        new SafeTreeMap<>((Comparator<? super K>) Ordering.natural().nullsFirst());

            

Reported by PMD.

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

Line: 47

                protected <K, V> NavigableMap<K, V> create() {
    @SuppressWarnings("unchecked")
    NavigableMap<K, V> innermost =
        new SafeTreeMap<>((Comparator<? super K>) Ordering.natural().nullsFirst());
    TestMap<K, V> inner = new TestMap<>(innermost, mutex);
    NavigableMap<K, V> outer = Synchronized.navigableMap(inner, mutex);
    return outer;
  }


            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 54

                }

  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;

            

Reported by PMD.

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

Line: 54

                }

  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;

            

Reported by PMD.

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

Line: 55

              
  static class TestEntry<K, V> extends ForwardingMapEntry<K, V> implements Serializable {
    private final Entry<K, V> delegate;
    private final Object mutex;

    TestEntry(Entry<K, V> delegate, Object mutex) {
      this.delegate = delegate;
      this.mutex = mutex;
    }

            

Reported by PMD.

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

Line: 101

                }

  static class TestMap<K, V> extends SynchronizedMapTest.TestMap<K, V>
      implements NavigableMap<K, V> {

    public TestMap(NavigableMap<K, V> delegate, Object mutex) {
      super(delegate, mutex);
    }


            

Reported by PMD.

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

Line: 115

                  @Override
    public Entry<K, V> ceilingEntry(K key) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate().ceilingEntry(key);
    }

    @Override
    public K ceilingKey(K key) {
      assertTrue(Thread.holdsLock(mutex));

            

Reported by PMD.

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

Line: 121

                  @Override
    public K ceilingKey(K key) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate().ceilingKey(key);
    }

    @Override
    public NavigableSet<K> descendingKeySet() {
      assertTrue(Thread.holdsLock(mutex));

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/QueuesTest.java
89 issues
This class has too many methods, consider refactoring it.
Design

Line: 50

               * @author Dimitris Andreou
 */

public class QueuesTest extends TestCase {
  /*
   * All the following tests relate to BlockingQueue methods in Queues.
   */

  public static List<BlockingQueue<Object>> blockingQueues() {

            

Reported by PMD.

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

Line: 70

                 * We need to perform operations in a thread pool, even for simple cases, because the queue might
   * be a SynchronousQueue.
   */
  private ExecutorService threadPool;

  @Override
  public void setUp() {
    threadPool = newCachedThreadPool();
  }

            

Reported by PMD.

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

Line: 72

                 */
  private ExecutorService threadPool;

  @Override
  public void setUp() {
    threadPool = newCachedThreadPool();
  }

  @Override

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 77

                  threadPool = newCachedThreadPool();
  }

  @Override
  public void tearDown() throws InterruptedException {
    threadPool.shutdown();
    assertTrue("Some worker didn't finish in time", threadPool.awaitTermination(10, SECONDS));
  }


            

Reported by PMD.

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

Line: 96

                      : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);
  }

  public void testMultipleProducers() throws Exception {
    for (BlockingQueue<Object> q : blockingQueues()) {
      testMultipleProducers(q);
    }
  }


            

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

                      : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);
  }

  public void testMultipleProducers() throws Exception {
    for (BlockingQueue<Object> q : blockingQueues()) {
      testMultipleProducers(q);
    }
  }


            

Reported by PMD.

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

Line: 102

                  }
  }

  private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));

            

Reported by PMD.

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

Line: 104

              
  private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 105

                private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 107

                    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError3 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored

            

Reported by PMD.

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

Line: 37

               * @author Louis Wasserman
 */
public class CompactLinkedHashMapTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MapTestSuiteBuilder.using(
                new TestStringMapGenerator() {
                  @Override

            

Reported by PMD.

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

Line: 67

                                @Override
                  protected Map<String, String> create(Entry<String, String>[] entries) {
                    CompactLinkedHashMap<String, String> map = CompactLinkedHashMap.create();
                    map.convertToHashFloodingResistantImplementation();
                    for (Entry<String, String> entry : entries) {
                      map.put(entry.getKey(), entry.getValue());
                    }
                    return map;
                  }

            

Reported by PMD.

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

Line: 89

                  return suite;
  }

  public void testInsertionOrder() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");

            

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

                  return suite;
  }

  public void testInsertionOrder() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");

            

Reported by PMD.

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

Line: 91

              
  public void testInsertionOrder() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");
    testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }

            

Reported by PMD.

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

Line: 92

                public void testInsertionOrder() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");
    testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }


            

Reported by PMD.

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

Line: 93

                  Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");
    testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }

  public void testInsertionOrderAfterPutKeyTwice() {

            

Reported by PMD.

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

Line: 94

                  map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");
    testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }

  public void testInsertionOrderAfterPutKeyTwice() {
    Map<Integer, String> map = CompactLinkedHashMap.create();

            

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

                  testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }

  public void testInsertionOrderAfterPutKeyTwice() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");

            

Reported by PMD.

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

Line: 98

                  testHasMapEntriesInOrder(map, 1, "a", 4, "b", 3, "d", 2, "c");
  }

  public void testInsertionOrderAfterPutKeyTwice() {
    Map<Integer, String> map = CompactLinkedHashMap.create();
    map.put(1, "a");
    map.put(4, "b");
    map.put(3, "d");
    map.put(2, "c");

            

Reported by PMD.

guava-tests/test/com/google/common/collect/QueuesTest.java
89 issues
This class has too many methods, consider refactoring it.
Design

Line: 50

               * @author Dimitris Andreou
 */

public class QueuesTest extends TestCase {
  /*
   * All the following tests relate to BlockingQueue methods in Queues.
   */

  public static List<BlockingQueue<Object>> blockingQueues() {

            

Reported by PMD.

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

Line: 70

                 * We need to perform operations in a thread pool, even for simple cases, because the queue might
   * be a SynchronousQueue.
   */
  private ExecutorService threadPool;

  @Override
  public void setUp() {
    threadPool = newCachedThreadPool();
  }

            

Reported by PMD.

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

Line: 72

                 */
  private ExecutorService threadPool;

  @Override
  public void setUp() {
    threadPool = newCachedThreadPool();
  }

  @Override

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 77

                  threadPool = newCachedThreadPool();
  }

  @Override
  public void tearDown() throws InterruptedException {
    threadPool.shutdown();
    assertTrue("Some worker didn't finish in time", threadPool.awaitTermination(10, SECONDS));
  }


            

Reported by PMD.

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

Line: 96

                      : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);
  }

  public void testMultipleProducers() throws Exception {
    for (BlockingQueue<Object> q : blockingQueues()) {
      testMultipleProducers(q);
    }
  }


            

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

                      : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);
  }

  public void testMultipleProducers() throws Exception {
    for (BlockingQueue<Object> q : blockingQueues()) {
      testMultipleProducers(q);
    }
  }


            

Reported by PMD.

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

Line: 102

                  }
  }

  private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));

            

Reported by PMD.

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

Line: 104

              
  private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 105

                private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
    for (boolean interruptibly : new boolean[] {true, false}) {
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 107

                    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError3 = threadPool.submit(new Producer(q, 20));
      @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored

            

Reported by PMD.