The following issues were found

guava-tests/benchmark/com/google/common/collect/ConcurrentHashMultisetBenchmark.java
40 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 49

               */
public class ConcurrentHashMultisetBenchmark {
  @Param({"1", "2", "4", "8"})
  int threads;

  @Param({"3", "30", "300"})
  int size;

  @Param MultisetSupplier implSupplier;

            

Reported by PMD.

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

Line: 52

                int threads;

  @Param({"3", "30", "300"})
  int size;

  @Param MultisetSupplier implSupplier;

  private Multiset<Integer> multiset;
  private ImmutableList<Integer> keys;

            

Reported by PMD.

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

Line: 54

                @Param({"3", "30", "300"})
  int size;

  @Param MultisetSupplier implSupplier;

  private Multiset<Integer> multiset;
  private ImmutableList<Integer> keys;
  private ExecutorService threadPool;


            

Reported by PMD.

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

Line: 56

              
  @Param MultisetSupplier implSupplier;

  private Multiset<Integer> multiset;
  private ImmutableList<Integer> keys;
  private ExecutorService threadPool;

  @BeforeExperiment
  void setUp() throws Exception {

            

Reported by PMD.

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

Line: 57

                @Param MultisetSupplier implSupplier;

  private Multiset<Integer> multiset;
  private ImmutableList<Integer> keys;
  private ExecutorService threadPool;

  @BeforeExperiment
  void setUp() throws Exception {
    multiset = implSupplier.get();

            

Reported by PMD.

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

Line: 58

              
  private Multiset<Integer> multiset;
  private ImmutableList<Integer> keys;
  private ExecutorService threadPool;

  @BeforeExperiment
  void setUp() throws Exception {
    multiset = implSupplier.get();
    ImmutableList.Builder<Integer> builder = ImmutableList.builder();

            

Reported by PMD.

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

Line: 60

                private ImmutableList<Integer> keys;
  private ExecutorService threadPool;

  @BeforeExperiment
  void setUp() throws Exception {
    multiset = implSupplier.get();
    ImmutableList.Builder<Integer> builder = ImmutableList.builder();
    for (int i = 0; i < size; i++) {
      builder.add(i);

            

Reported by PMD.

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

Line: 61

                private ExecutorService threadPool;

  @BeforeExperiment
  void setUp() throws Exception {
    multiset = implSupplier.get();
    ImmutableList.Builder<Integer> builder = ImmutableList.builder();
    for (int i = 0; i < size; i++) {
      builder.add(i);
    }

            

Reported by PMD.

Possible God Class (WMC=51, ATFD=7, TCC=24.308%)
Design

Line: 168

                 * Duplication of the old version of ConcurrentHashMultiset (with some unused stuff removed, like
   * serialization code) which used a map with boxed integers for the values.
   */
  private static final class OldConcurrentHashMultiset<E> extends AbstractMultiset<E> {
    /** The number of occurrences of each element. */
    private final transient ConcurrentMap<E, Integer> countMap;

    /**
     * Creates a new, empty {@code OldConcurrentHashMultiset} using the default initial capacity,

            

Reported by PMD.

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

Line: 168

                 * Duplication of the old version of ConcurrentHashMultiset (with some unused stuff removed, like
   * serialization code) which used a map with boxed integers for the values.
   */
  private static final class OldConcurrentHashMultiset<E> extends AbstractMultiset<E> {
    /** The number of occurrences of each element. */
    private final transient ConcurrentMap<E, Integer> countMap;

    /**
     * Creates a new, empty {@code OldConcurrentHashMultiset} using the default initial capacity,

            

Reported by PMD.

guava-tests/test/com/google/common/collect/PeekingIteratorTest.java
39 issues
Private field 'master' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 53

                 * #remove()}.
   */
  private static class PeekingIteratorTester<T> extends IteratorTester<T> {
    private Iterable<T> master;
    private List<T> targetList;

    public PeekingIteratorTester(Collection<T> master) {
      super(master.size() + 3, MODIFIABLE, master, IteratorTester.KnownOrder.KNOWN_ORDER);
      this.master = master;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 72

                  @Override
    protected void verify(List<T> elements) {
      // verify same objects were removed from reference and target
      assertEquals(elements, targetList);
    }
  }

  private <T> void actsLikeIteratorHelper(final List<T> list) {
    // Check with modifiable copies of the list

            

Reported by PMD.

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

Line: 85

                      list.size() * 2 + 2, UNMODIFIABLE, list, IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<T> newTargetIterator() {
        Iterator<T> iterator = Collections.unmodifiableList(list).iterator();
        return Iterators.peekingIterator(iterator);
      }
    }.test();
  }


            

Reported by PMD.

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

Line: 91

                  }.test();
  }

  public void testPeekingIteratorBehavesLikeIteratorOnEmptyIterable() {
    actsLikeIteratorHelper(Collections.emptyList());
  }

  public void testPeekingIteratorBehavesLikeIteratorOnSingletonIterable() {
    actsLikeIteratorHelper(Collections.singletonList(new Object()));

            

Reported by PMD.

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

Line: 91

                  }.test();
  }

  public void testPeekingIteratorBehavesLikeIteratorOnEmptyIterable() {
    actsLikeIteratorHelper(Collections.emptyList());
  }

  public void testPeekingIteratorBehavesLikeIteratorOnSingletonIterable() {
    actsLikeIteratorHelper(Collections.singletonList(new Object()));

            

Reported by PMD.

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

Line: 95

                  actsLikeIteratorHelper(Collections.emptyList());
  }

  public void testPeekingIteratorBehavesLikeIteratorOnSingletonIterable() {
    actsLikeIteratorHelper(Collections.singletonList(new Object()));
  }

  // TODO(cpovirk): instead of skipping, use a smaller number of steps
  @GwtIncompatible // works but takes 5 minutes to run

            

Reported by PMD.

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

Line: 95

                  actsLikeIteratorHelper(Collections.emptyList());
  }

  public void testPeekingIteratorBehavesLikeIteratorOnSingletonIterable() {
    actsLikeIteratorHelper(Collections.singletonList(new Object()));
  }

  // TODO(cpovirk): instead of skipping, use a smaller number of steps
  @GwtIncompatible // works but takes 5 minutes to run

            

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

                }

  // TODO(cpovirk): instead of skipping, use a smaller number of steps
  @GwtIncompatible // works but takes 5 minutes to run
  public void testPeekingIteratorBehavesLikeIteratorOnThreeElementIterable() {
    actsLikeIteratorHelper(Lists.newArrayList("A", "B", "C"));
  }

  @GwtIncompatible // works but takes 5 minutes to run

            

Reported by PMD.

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

Line: 101

              
  // TODO(cpovirk): instead of skipping, use a smaller number of steps
  @GwtIncompatible // works but takes 5 minutes to run
  public void testPeekingIteratorBehavesLikeIteratorOnThreeElementIterable() {
    actsLikeIteratorHelper(Lists.newArrayList("A", "B", "C"));
  }

  @GwtIncompatible // works but takes 5 minutes to run
  public void testPeekingIteratorAcceptsNullElements() {

            

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

                  actsLikeIteratorHelper(Lists.newArrayList("A", "B", "C"));
  }

  @GwtIncompatible // works but takes 5 minutes to run
  public void testPeekingIteratorAcceptsNullElements() {
    actsLikeIteratorHelper(Lists.newArrayList(null, "A", null));
  }

  public void testPeekOnEmptyList() {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/MapsCollectionTest.java
39 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.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.testing.Helpers.mapEntry;


            

Reported by PMD.

The class 'MapsCollectionTest' has a Standard Cyclomatic Complexity of 4 (Highest = 30).
Design

Line: 62

               *
 * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(

            

Reported by PMD.

The class 'MapsCollectionTest' has a Modified Cyclomatic Complexity of 4 (Highest = 30).
Design

Line: 62

               *
 * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 62

               *
 * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 62

               *
 * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(

            

Reported by PMD.

The method 'suite' has a Standard Cyclomatic Complexity of 30.
Design

Line: 63

               * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

Reported by PMD.

The method 'suite' has a Modified Cyclomatic Complexity of 30.
Design

Line: 63

               * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

Reported by PMD.

JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 63

               * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

Reported by PMD.

Avoid really long methods.
Design

Line: 63

               * @author Louis Wasserman
 */
public class MapsCollectionTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        NavigableMapTestSuiteBuilder.using(
                new TestStringSortedMapGenerator() {

            

Reported by PMD.

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

Line: 120

                                  Set<String> set = Sets.newLinkedHashSet();
                    for (Object e : elements) {
                      Entry<?, ?> entry = (Entry<?, ?>) e;
                      checkNotNull(entry.getValue());
                      set.add((String) checkNotNull(entry.getKey()));
                    }
                    return Maps.asMap(
                        set,
                        new Function<String, Integer>() {

            

Reported by PMD.

guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java
39 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 37

               */
public class LittleEndianDataInputStreamTest extends TestCase {

  private byte[] data;

  @Override
  protected void setUp() throws Exception {
    super.setUp();


            

Reported by PMD.

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

Line: 39

              
  private byte[] data;

  @Override
  protected void setUp() throws Exception {
    super.setUp();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);

            

Reported by PMD.

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

Line: 69

                  out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL));
  }

  public void testReadFully() throws IOException {
    DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data));
    byte[] b = new byte[data.length];
    in.readFully(b);
    assertEquals(Bytes.asList(data), Bytes.asList(b));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 73

                  DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data));
    byte[] b = new byte[data.length];
    in.readFully(b);
    assertEquals(Bytes.asList(data), Bytes.asList(b));
  }

  public void testReadUnsignedByte_eof() throws IOException {
    DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(new byte[0]));
    try {

            

Reported by PMD.

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

Line: 76

                  assertEquals(Bytes.asList(data), Bytes.asList(b));
  }

  public void testReadUnsignedByte_eof() throws IOException {
    DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(new byte[0]));
    try {
      in.readUnsignedByte();
      fail();
    } catch (EOFException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 80

                  DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(new byte[0]));
    try {
      in.readUnsignedByte();
      fail();
    } catch (EOFException expected) {
    }
  }

  public void testReadUnsignedShort_eof() throws IOException {

            

Reported by PMD.

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

Line: 80

                  DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(new byte[0]));
    try {
      in.readUnsignedByte();
      fail();
    } catch (EOFException expected) {
    }
  }

  public void testReadUnsignedShort_eof() throws IOException {

            

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

                  }
  }

  public void testReadUnsignedShort_eof() throws IOException {
    byte[] buf = {23};
    DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(buf));
    try {
      in.readUnsignedShort();
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 90

                  DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(buf));
    try {
      in.readUnsignedShort();
      fail();
    } catch (EOFException expected) {
    }
  }

  public void testReadLine() throws IOException {

            

Reported by PMD.

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

Line: 90

                  DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(buf));
    try {
      in.readUnsignedShort();
      fail();
    } catch (EOFException expected) {
    }
  }

  public void testReadLine() throws IOException {

            

Reported by PMD.

guava-testlib/test/com/google/common/testing/EquivalenceTesterTest.java
39 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 37

               */
@GwtCompatible
public class EquivalenceTesterTest extends TestCase {
  private EquivalenceTester<Object> tester;
  private MockEquivalence equivalenceMock;

  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 38

              @GwtCompatible
public class EquivalenceTesterTest extends TestCase {
  private EquivalenceTester<Object> tester;
  private MockEquivalence equivalenceMock;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    this.equivalenceMock = new MockEquivalence();

            

Reported by PMD.

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

Line: 40

                private EquivalenceTester<Object> tester;
  private MockEquivalence equivalenceMock;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    this.equivalenceMock = new MockEquivalence();
    this.tester = EquivalenceTester.of(equivalenceMock);
  }

            

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

                }

  /** Test null reference yields error */
  public void testOf_NullPointerException() {
    try {
      EquivalenceTester.of(null);
      fail("Should fail on null reference");
    } catch (NullPointerException expected) {
    }

            

Reported by PMD.

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

Line: 51

                public void testOf_NullPointerException() {
    try {
      EquivalenceTester.of(null);
      fail("Should fail on null reference");
    } catch (NullPointerException expected) {
    }
  }

  public void testTest_NoData() {

            

Reported by PMD.

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

Line: 52

                  try {
      EquivalenceTester.of(null);
      fail("Should fail on null reference");
    } catch (NullPointerException expected) {
    }
  }

  public void testTest_NoData() {
    tester.test();

            

Reported by PMD.

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

Line: 52

                  try {
      EquivalenceTester.of(null);
      fail("Should fail on null reference");
    } catch (NullPointerException expected) {
    }
  }

  public void testTest_NoData() {
    tester.test();

            

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

                  }
  }

  public void testTest_NoData() {
    tester.test();
  }

  public void testTest() {
    Object group1Item1 = new TestObject(1, 1);

            

Reported by PMD.

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

Line: 56

                  }
  }

  public void testTest_NoData() {
    tester.test();
  }

  public void testTest() {
    Object group1Item1 = new TestObject(1, 1);

            

Reported by PMD.

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

Line: 60

                  tester.test();
  }

  public void testTest() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);
    Object group2Item1 = new TestObject(2, 1);
    Object group2Item2 = new TestObject(2, 2);


            

Reported by PMD.

guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java
39 issues
This class has too many methods, consider refactoring it.
Design

Line: 29

               * @author Patrick Costello
 * @author Kurt Alfred Kluever
 */
public class Crc32cHashFunctionTest extends TestCase {
  public void testEmpty() {
    assertCrc(0, new byte[0]);
  }

  public void testZeros() {

            

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

               * @author Kurt Alfred Kluever
 */
public class Crc32cHashFunctionTest extends TestCase {
  public void testEmpty() {
    assertCrc(0, new byte[0]);
  }

  public void testZeros() {
    // Test 32 byte array of 0x00.

            

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

                  assertCrc(0, new byte[0]);
  }

  public void testZeros() {
    // Test 32 byte array of 0x00.
    byte[] zeros = new byte[32];
    assertCrc(0x8a9136aa, zeros);
  }


            

Reported by PMD.

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

Line: 40

                  assertCrc(0x8a9136aa, zeros);
  }

  public void testZeros100() {
    // Test 100 byte array of 0x00.
    byte[] zeros = new byte[100];
    assertCrc(0x07cb9ff6, zeros);
  }


            

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

                  assertCrc(0x07cb9ff6, zeros);
  }

  public void testFull() {
    // Test 32 byte array of 0xFF.
    byte[] fulls = new byte[32];
    Arrays.fill(fulls, (byte) 0xFF);
    assertCrc(0x62a8ab43, fulls);
  }

            

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

                  assertCrc(0x62a8ab43, fulls);
  }

  public void testFull100() {
    // Test 100 byte array of 0xFF.
    byte[] fulls = new byte[100];
    Arrays.fill(fulls, (byte) 0xFF);
    assertCrc(0xbc753add, fulls);
  }

            

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

                  assertCrc(0xbc753add, fulls);
  }

  public void testAscending() {
    // Test 32 byte arrays of ascending.
    byte[] ascending = new byte[32];
    for (int i = 0; i < 32; i++) {
      ascending[i] = (byte) i;
    }

            

Reported by PMD.

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

Line: 69

                  assertCrc(0x46dd794e, ascending);
  }

  public void testDescending() {
    // Test 32 byte arrays of descending.
    byte[] descending = new byte[32];
    for (int i = 0; i < 32; i++) {
      descending[i] = (byte) (31 - i);
    }

            

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

                  assertCrc(0x113fdb5c, descending);
  }

  public void testDescending100() {
    // Test 100 byte arrays of descending.
    byte[] descending = new byte[100];
    for (int i = 0; i < 100; i++) {
      descending[i] = (byte) (99 - i);
    }

            

Reported by PMD.

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

Line: 87

                  assertCrc(0xd022db97, descending);
  }

  public void testScsiReadCommand() {
    // Test SCSI read command.
    byte[] scsiReadCommand =
        new byte[] {
          0x01, (byte) 0xc0, 0x00, 0x00,
          0x00, 0x00, 0x00, 0x00,

            

Reported by PMD.

android/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java
39 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 92

              
  public void testGetSubtypeOf_impossibleWildcard() {
    TypeToken<List<? extends Number>> numberList = new TypeToken<List<? extends Number>>() {};
    abstract class StringList implements List<String> {}
    try {
      numberList.getSubtype(StringList.class);
      fail();
    } catch (IllegalArgumentException expected) {
    }

            

Reported by PMD.

No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 501

                private static class Mall<T> {
    class Shop<ProductT> {}

    abstract class Retailer<ProductT> extends Shop<ProductT>
        implements Comparator<ProductT>, ConsumerFacing<ProductT> {}
  }

  private static class Outlet<T> extends Mall<T> {}


            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.reflect;

import static com.google.common.truth.Truth.assertThat;

import java.io.Serializable;
import java.util.Comparator;

            

Reported by PMD.

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

Line: 29

              @AndroidIncompatible // lots of failures, possibly some related to bad equals() implementations?
public class TypeTokenSubtypeTest extends TestCase {

  public void testOwnerTypeSubtypes() throws Exception {
    new OwnerTypeSubtypingTests().testAllDeclarations();
  }

  public void testWildcardSubtypes() throws Exception {
    new WildcardSubtypingTests().testAllDeclarations();

            

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

              @AndroidIncompatible // lots of failures, possibly some related to bad equals() implementations?
public class TypeTokenSubtypeTest extends TestCase {

  public void testOwnerTypeSubtypes() throws Exception {
    new OwnerTypeSubtypingTests().testAllDeclarations();
  }

  public void testWildcardSubtypes() throws Exception {
    new WildcardSubtypingTests().testAllDeclarations();

            

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

                  new OwnerTypeSubtypingTests().testAllDeclarations();
  }

  public void testWildcardSubtypes() throws Exception {
    new WildcardSubtypingTests().testAllDeclarations();
  }

  /**
   * This test reproduces the bug in canonicalizeWildcardType() when the type variable is

            

Reported by PMD.

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

Line: 33

                  new OwnerTypeSubtypingTests().testAllDeclarations();
  }

  public void testWildcardSubtypes() throws Exception {
    new WildcardSubtypingTests().testAllDeclarations();
  }

  /**
   * This test reproduces the bug in canonicalizeWildcardType() when the type variable is

            

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

                 * This test reproduces the bug in canonicalizeWildcardType() when the type variable is
   * recursively bounded.
   */
  public void testRecursiveWildcardSubtypeBug() throws Exception {
    try {
      new RecursiveTypeBoundBugExample<>().testAllDeclarations();
      fail();
    } catch (Exception e) {
      assertThat(e).hasCauseThat().isInstanceOf(AssertionError.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                public void testRecursiveWildcardSubtypeBug() throws Exception {
    try {
      new RecursiveTypeBoundBugExample<>().testAllDeclarations();
      fail();
    } catch (Exception e) {
      assertThat(e).hasCauseThat().isInstanceOf(AssertionError.class);
    }
  }


            

Reported by PMD.

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

Line: 45

                  try {
      new RecursiveTypeBoundBugExample<>().testAllDeclarations();
      fail();
    } catch (Exception e) {
      assertThat(e).hasCauseThat().isInstanceOf(AssertionError.class);
    }
  }

  public void testSubtypeOfInnerClass_nonStaticAnonymousClass() {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/Helpers.java
39 issues
Avoid throwing null pointer exceptions.
Design

Line: 456

              
    protected NullsBefore(String justAfterNull) {
      if (justAfterNull == null) {
        throw new NullPointerException();
      }

      this.justAfterNull = justAfterNull;
    }


            

Reported by PMD.

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

Line: 44

              import junit.framework.AssertionFailedError;

@GwtCompatible(emulated = true)
public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }


            

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

              import junit.framework.AssertionFailedError;

@GwtCompatible(emulated = true)
public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }


            

Reported by PMD.

Possible God Class (WMC=58, ATFD=18, TCC=0.000%)
Design

Line: 44

              import junit.framework.AssertionFailedError;

@GwtCompatible(emulated = true)
public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }


            

Reported by PMD.

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

Line: 44

              import junit.framework.AssertionFailedError;

@GwtCompatible(emulated = true)
public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }


            

Reported by PMD.

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

Line: 44

              import junit.framework.AssertionFailedError;

@GwtCompatible(emulated = true)
public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 47

              public class Helpers {
  // Clone of Objects.equal
  static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }

  // Clone of Lists.newArrayList
  public static <E> List<E> copyToList(Iterable<? extends E> elements) {
    List<E> list = new ArrayList<E>();

            

Reported by PMD.

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

Line: 74

              
  // Would use Maps.immutableEntry
  public static <K, V> Entry<K, V> mapEntry(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  private static boolean isEmpty(Iterable<?> iterable) {
    return iterable instanceof Collection
        ? ((Collection<?>) iterable).isEmpty()

            

Reported by PMD.

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

Line: 74

              
  // Would use Maps.immutableEntry
  public static <K, V> Entry<K, V> mapEntry(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  private static boolean isEmpty(Iterable<?> iterable) {
    return iterable instanceof Collection
        ? ((Collection<?>) iterable).isEmpty()

            

Reported by PMD.

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

Line: 74

              
  // Would use Maps.immutableEntry
  public static <K, V> Entry<K, V> mapEntry(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  private static boolean isEmpty(Iterable<?> iterable) {
    return iterable instanceof Collection
        ? ((Collection<?>) iterable).isEmpty()

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapKeysTester.java
39 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: 44

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapKeysTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(SEVERAL)
  public void testKeys() {
    resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
    Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));

            

Reported by PMD.

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

Line: 45

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapKeysTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(SEVERAL)
  public void testKeys() {
    resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
    Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));
    assertEquals(1, keys.count(k1()));

            

Reported by PMD.

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

Line: 48

                public void testKeys() {
    resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
    Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));
    assertEquals(1, keys.count(k1()));
    assertEquals(3, keys.size());
    assertContainsAllOf(keys, k0(), k1());
    assertContainsAllOf(

            

Reported by PMD.

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

Line: 49

                  resetContainer(
        Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
    Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));
    assertEquals(1, keys.count(k1()));
    assertEquals(3, keys.size());
    assertContainsAllOf(keys, k0(), k1());
    assertContainsAllOf(
        keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));

            

Reported by PMD.

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

Line: 50

                      Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
    Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));
    assertEquals(1, keys.count(k1()));
    assertEquals(3, keys.size());
    assertContainsAllOf(keys, k0(), k1());
    assertContainsAllOf(
        keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
  }

            

Reported by PMD.

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

Line: 51

                  Multiset<K> keys = multimap().keys();
    assertEquals(2, keys.count(k0()));
    assertEquals(1, keys.count(k1()));
    assertEquals(3, keys.size());
    assertContainsAllOf(keys, k0(), k1());
    assertContainsAllOf(
        keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
  }


            

Reported by PMD.

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

Line: 54

                  assertEquals(3, keys.size());
    assertContainsAllOf(keys, k0(), k1());
    assertContainsAllOf(
        keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testKeysCountAbsentNullKey() {
    assertEquals(0, multimap().keys().count(null));

            

Reported by PMD.

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

Line: 57

                      keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testKeysCountAbsentNullKey() {
    assertEquals(0, multimap().keys().count(null));
  }

  @CollectionSize.Require(SEVERAL)

            

Reported by PMD.

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

Line: 59

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testKeysCountAbsentNullKey() {
    assertEquals(0, multimap().keys().count(null));
  }

  @CollectionSize.Require(SEVERAL)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testKeysWithNullKey() {

            

Reported by PMD.

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

Line: 59

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testKeysCountAbsentNullKey() {
    assertEquals(0, multimap().keys().count(null));
  }

  @CollectionSize.Require(SEVERAL)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testKeysWithNullKey() {

            

Reported by PMD.

android/guava/src/com/google/common/collect/ImmutableList.java
39 issues
Using multiple unary operators may be a bug, and/or is confusing.
Error

Line: 648

                  for (int i = 0; i < n; i++) {
      hashCode = 31 * hashCode + get(i).hashCode();

      hashCode = ~~hashCode;
      // needed to deal with GWT integer overflow
    }
    return hashCode;
  }


            

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 static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndex;

            

Reported by PMD.

Possible God Class (WMC=64, ATFD=9, TCC=0.000%)
Design

Line: 61

              @GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableList<E> extends ImmutableCollection<E>
    implements List<E>, RandomAccess {
  /**
   * Returns the empty immutable list. This list behaves and performs comparably to {@link
   * Collections#emptyList}, and is preferable mainly for consistency and maintainability of your
   * code.

            

Reported by PMD.

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

Line: 62

              @SuppressWarnings("serial") // we're overriding default serialization
@ElementTypesAreNonnullByDefault
public abstract class ImmutableList<E> extends ImmutableCollection<E>
    implements List<E>, RandomAccess {
  /**
   * Returns the empty immutable list. This list behaves and performs comparably to {@link
   * Collections#emptyList}, and is preferable mainly for consistency and maintainability of your
   * code.
   *

            

Reported by PMD.

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

Line: 71

                 * <p><b>Performance note:</b> the instance returned is a singleton.
   */
  // Casting to any type is safe because the list will never hold any elements.
  @SuppressWarnings("unchecked")
  public static <E> ImmutableList<E> of() {
    return (ImmutableList<E>) EMPTY;
  }

  /**

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 164

                 *
   * @throws NullPointerException if any element is null
   */
  public static <E> ImmutableList<E> of(
      E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) {
    return construct(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);
  }

  /**

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 174

                 *
   * @throws NullPointerException if any element is null
   */
  public static <E> ImmutableList<E> of(
      E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) {
    return construct(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11);
  }

  // These go up to eleven. After that, you just get the varargs form, and

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 191

                 * @since 3.0 (source-compatible since 2.0)
   */
  @SafeVarargs // For Eclipse. For internal javac we have disabled this pointless type of warning.
  public static <E> ImmutableList<E> of(
      E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11, E e12, E... others) {
    checkArgument(
        others.length <= Integer.MAX_VALUE - 12, "the total number of elements must fit in an int");
    Object[] array = new Object[12 + others.length];
    array[0] = e1;

            

Reported by PMD.

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

Line: 247

                  if (elements instanceof ImmutableCollection) {
      @SuppressWarnings("unchecked") // all supported methods are covariant
      ImmutableList<E> list = ((ImmutableCollection<E>) elements).asList();
      return list.isPartialView() ? ImmutableList.<E>asImmutableList(list.toArray()) : list;
    }
    return construct(elements.toArray());
  }

  /**

            

Reported by PMD.

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

Line: 247

                  if (elements instanceof ImmutableCollection) {
      @SuppressWarnings("unchecked") // all supported methods are covariant
      ImmutableList<E> list = ((ImmutableCollection<E>) elements).asList();
      return list.isPartialView() ? ImmutableList.<E>asImmutableList(list.toArray()) : list;
    }
    return construct(elements.toArray());
  }

  /**

            

Reported by PMD.