The following issues were found

guava-tests/test/com/google/common/collect/SynchronizedQueueTest.java
43 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 36

                  TestQueue<String> inner = new TestQueue<>();
    Queue<String> outer = Synchronized.queue(inner, null);
    inner.mutex = outer;
    outer.add("foo"); // necessary because we try to remove elements later on
    return outer;
  }

  private static final class TestQueue<E> implements Queue<E> {
    private final Queue<E> delegate = Lists.newLinkedList();

            

Reported by PMD.

The String literal 'foo' appears 11 times in this file; the first occurrence is on line 36
Error

Line: 36

                  TestQueue<String> inner = new TestQueue<>();
    Queue<String> outer = Synchronized.queue(inner, null);
    inner.mutex = outer;
    outer.add("foo"); // necessary because we try to remove elements later on
    return outer;
  }

  private static final class TestQueue<E> implements Queue<E> {
    private final Queue<E> delegate = Lists.newLinkedList();

            

Reported by PMD.

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

Line: 40

                  return outer;
  }

  private static final class TestQueue<E> implements Queue<E> {
    private final Queue<E> delegate = Lists.newLinkedList();
    public Object mutex;

    @Override
    public boolean offer(E o) {

            

Reported by PMD.

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

Line: 41

                }

  private static final class TestQueue<E> implements Queue<E> {
    private final Queue<E> delegate = Lists.newLinkedList();
    public Object mutex;

    @Override
    public boolean offer(E o) {
      assertTrue(Thread.holdsLock(mutex));

            

Reported by PMD.

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

Line: 42

              
  private static final class TestQueue<E> implements Queue<E> {
    private final Queue<E> delegate = Lists.newLinkedList();
    public Object mutex;

    @Override
    public boolean offer(E o) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.offer(o);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

              
    @Override
    public boolean offer(E o) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.offer(o);
    }

    @Override
    public E poll() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 52

              
    @Override
    public E poll() {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.poll();
    }

    @Override
    public E remove() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 58

              
    @Override
    public E remove() {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.remove();
    }

    @Override
    public boolean remove(Object object) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

              
    @Override
    public boolean remove(Object object) {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.remove(object);
    }

    @Override
    public E peek() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 70

              
    @Override
    public E peek() {
      assertTrue(Thread.holdsLock(mutex));
      return delegate.peek();
    }

    @Override
    public E element() {

            

Reported by PMD.

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

Line: 85

                   * because we know that newClassMap() is implemented using ConstrainedMap which is itself
     * well-tested. A purist would object to this, but what can I say, we're dirty cheaters.
     */
    map.put(Integer.class, new Integer(5));
    try {
      map.put(Double.class, new Long(42));
      fail();
    } catch (ClassCastException expected) {
    }

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 87

                   */
    map.put(Integer.class, new Integer(5));
    try {
      map.put(Double.class, new Long(42));
      fail();
    } catch (ClassCastException expected) {
    }
    // Won't compile: map.put(String.class, "x");
  }

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 95

                }

  public void testPutAndGetInstance() {
    assertNull(map.putInstance(Integer.class, new Integer(5)));

    Integer oldValue = map.putInstance(Integer.class, new Integer(7));
    assertEquals(5, (int) oldValue);

    Integer newValue = map.getInstance(Integer.class);

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 97

                public void testPutAndGetInstance() {
    assertNull(map.putInstance(Integer.class, new Integer(5)));

    Integer oldValue = map.putInstance(Integer.class, new Integer(7));
    assertEquals(5, (int) oldValue);

    Integer newValue = map.getInstance(Integer.class);
    assertEquals(7, (int) newValue);


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 108

              
  public void testNull() {
    try {
      map.put(null, new Integer(1));
      fail();
    } catch (NullPointerException expected) {
    }
    map.putInstance(Integer.class, null);
    assertNull(map.get(Integer.class));

            

Reported by PMD.

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

Line: 37

               * @author Kevin Bourrillion
 */
public class MutableClassToInstanceMapTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(MutableClassToInstanceMapTest.class);

    suite.addTest(
        MapTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 52

                                  MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
                    for (Object object : elements) {
                      Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
                      map.putInstance(entry.getKey(), entry.getValue());
                    }
                    return (Map) map;
                  }
                })
            .named("MutableClassToInstanceMap")

            

Reported by PMD.

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

Line: 52

                                  MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
                    for (Object object : elements) {
                      Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
                      map.putInstance(entry.getKey(), entry.getValue());
                    }
                    return (Map) map;
                  }
                })
            .named("MutableClassToInstanceMap")

            

Reported by PMD.

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

Line: 71

                  return suite;
  }

  private ClassToInstanceMap<Number> map;

  @Override
  protected void setUp() throws Exception {
    map = MutableClassToInstanceMap.create();
  }

            

Reported by PMD.

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

Line: 73

              
  private ClassToInstanceMap<Number> map;

  @Override
  protected void setUp() throws Exception {
    map = MutableClassToInstanceMap.create();
  }

  public void testConstraint() {

            

Reported by PMD.

guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
42 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: 106

                @ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2})
  private static class ExampleDerivedInterfaceTester extends ExampleBaseInterfaceTester {
    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleDerivedFeature.Require({
      ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_2
    })
    public void testRequiringTwoExplicitDerivedFeatures() throws Exception {

            

Reported by PMD.

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

Line: 111

                    ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_2
    })
    public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
      doNotActuallyRunThis();
    }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")

            

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

                  }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleDerivedFeature.Require({
      ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_3
    })
    public void testRequiringAllThreeDerivedFeatures() {

            

Reported by PMD.

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

Line: 121

                    ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_3
    })
    public void testRequiringAllThreeDerivedFeatures() {
      doNotActuallyRunThis();
    }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")

            

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

                  }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
    public void testRequiringConflictingFeatures() throws Exception {
      doNotActuallyRunThis();
    }
  }

            

Reported by PMD.

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

Line: 128

                  // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
    public void testRequiringConflictingFeatures() throws Exception {
      doNotActuallyRunThis();
    }
  }

  @ExampleDerivedFeature.Require(absent = {ExampleDerivedFeature.DERIVED_FEATURE_2})

            

Reported by PMD.

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

Line: 137

                private static class ConflictingRequirementsExampleDerivedInterfaceTester
      extends ExampleBaseInterfaceTester {}

  public void testTestFeatureEnums() throws Exception {
    // Haha! Let's test our own test rig!
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }


            

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

                private static class ConflictingRequirementsExampleDerivedInterfaceTester
      extends ExampleBaseInterfaceTester {}

  public void testTestFeatureEnums() throws Exception {
    // Haha! Let's test our own test rig!
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }


            

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

                  FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }

  public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
    assertSame(features, FeatureUtil.addImpliedFeatures(features));
  }

  public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 145

              
  public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
    assertSame(features, FeatureUtil.addImpliedFeatures(features));
  }

  public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
    Set<Feature<?>> features;


            

Reported by PMD.

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

Line: 35

               */
public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */

            

Reported by PMD.

Private field 'baos' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 35

               */
public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */

            

Reported by PMD.

Private field 'out' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 36

              public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});

            

Reported by PMD.

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

Line: 36

              public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});

            

Reported by PMD.

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

Line: 38

                private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});
    out.writeBoolean(true);
    out.writeBoolean(false);

            

Reported by PMD.

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

Line: 38

                private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});
    out.writeBoolean(true);
    out.writeBoolean(false);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  /* Read in various values NORMALLY */
    byte[] b = new byte[2];
    in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 65

                  byte[] b = new byte[2];
    in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());

            

Reported by PMD.

Use assertTrue(x)/assertFalse(x) instead of assertEquals(true, x)/assertEquals(false, x) or assertEquals(Boolean.TRUE, x)/assertEquals(Boolean.FALSE, x).
Design

Line: 66

                  in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());
    assertEquals('\u6100', in.readChar());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 66

                  in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());
    assertEquals('\u6100', in.readChar());

            

Reported by PMD.

android/guava/src/com/google/common/io/CharSource.java
42 issues
This class has too many methods, consider refactoring it.
Design

Line: 81

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class CharSource {

  /** Constructor for use by subclasses. */
  protected CharSource() {}

  /**

            

Reported by PMD.

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

Line: 168

                @Beta
  public long length() throws IOException {
    Optional<Long> lengthIfKnown = lengthIfKnown();
    if (lengthIfKnown.isPresent()) {
      return lengthIfKnown.get();
    }

    Closer closer = Closer.create();
    try {

            

Reported by PMD.

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

Line: 174

              
    Closer closer = Closer.create();
    try {
      Reader reader = closer.register(openStream());
      return countBySkipping(reader);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 176

                  try {
      Reader reader = closer.register(openStream());
      return countBySkipping(reader);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 186

                private long countBySkipping(Reader reader) throws IOException {
    long count = 0;
    long read;
    while ((read = reader.skip(Long.MAX_VALUE)) != 0) {
      count += read;
    }
    return count;
  }


            

Reported by PMD.

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

Line: 206

              
    Closer closer = Closer.create();
    try {
      Reader reader = closer.register(openStream());
      return CharStreams.copy(reader, appendable);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 208

                  try {
      Reader reader = closer.register(openStream());
      return CharStreams.copy(reader, appendable);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 228

              
    Closer closer = Closer.create();
    try {
      Reader reader = closer.register(openStream());
      Writer writer = closer.register(sink.openStream());
      return CharStreams.copy(reader, writer);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 229

                  Closer closer = Closer.create();
    try {
      Reader reader = closer.register(openStream());
      Writer writer = closer.register(sink.openStream());
      return CharStreams.copy(reader, writer);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 231

                    Reader reader = closer.register(openStream());
      Writer writer = closer.register(sink.openStream());
      return CharStreams.copy(reader, writer);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
42 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: 106

                @ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2})
  private static class ExampleDerivedInterfaceTester extends ExampleBaseInterfaceTester {
    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleDerivedFeature.Require({
      ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_2
    })
    public void testRequiringTwoExplicitDerivedFeatures() throws Exception {

            

Reported by PMD.

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

Line: 111

                    ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_2
    })
    public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
      doNotActuallyRunThis();
    }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")

            

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

                  }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleDerivedFeature.Require({
      ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_3
    })
    public void testRequiringAllThreeDerivedFeatures() {

            

Reported by PMD.

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

Line: 121

                    ExampleDerivedFeature.DERIVED_FEATURE_1,
      ExampleDerivedFeature.DERIVED_FEATURE_3
    })
    public void testRequiringAllThreeDerivedFeatures() {
      doNotActuallyRunThis();
    }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")

            

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

                  }

    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
    public void testRequiringConflictingFeatures() throws Exception {
      doNotActuallyRunThis();
    }
  }

            

Reported by PMD.

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

Line: 128

                  // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
    public void testRequiringConflictingFeatures() throws Exception {
      doNotActuallyRunThis();
    }
  }

  @ExampleDerivedFeature.Require(absent = {ExampleDerivedFeature.DERIVED_FEATURE_2})

            

Reported by PMD.

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

Line: 137

                private static class ConflictingRequirementsExampleDerivedInterfaceTester
      extends ExampleBaseInterfaceTester {}

  public void testTestFeatureEnums() throws Exception {
    // Haha! Let's test our own test rig!
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }


            

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

                private static class ConflictingRequirementsExampleDerivedInterfaceTester
      extends ExampleBaseInterfaceTester {}

  public void testTestFeatureEnums() throws Exception {
    // Haha! Let's test our own test rig!
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
    FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }


            

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

                  FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
  }

  public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
    assertSame(features, FeatureUtil.addImpliedFeatures(features));
  }

  public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 145

              
  public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
    assertSame(features, FeatureUtil.addImpliedFeatures(features));
  }

  public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
    Set<Feature<?>> features;


            

Reported by PMD.

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

Line: 85

                   * because we know that newClassMap() is implemented using ConstrainedMap which is itself
     * well-tested. A purist would object to this, but what can I say, we're dirty cheaters.
     */
    map.put(Integer.class, new Integer(5));
    try {
      map.put(Double.class, new Long(42));
      fail();
    } catch (ClassCastException expected) {
    }

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 87

                   */
    map.put(Integer.class, new Integer(5));
    try {
      map.put(Double.class, new Long(42));
      fail();
    } catch (ClassCastException expected) {
    }
    // Won't compile: map.put(String.class, "x");
  }

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 95

                }

  public void testPutAndGetInstance() {
    assertNull(map.putInstance(Integer.class, new Integer(5)));

    Integer oldValue = map.putInstance(Integer.class, new Integer(7));
    assertEquals(5, (int) oldValue);

    Integer newValue = map.getInstance(Integer.class);

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 97

                public void testPutAndGetInstance() {
    assertNull(map.putInstance(Integer.class, new Integer(5)));

    Integer oldValue = map.putInstance(Integer.class, new Integer(7));
    assertEquals(5, (int) oldValue);

    Integer newValue = map.getInstance(Integer.class);
    assertEquals(7, (int) newValue);


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 108

              
  public void testNull() {
    try {
      map.put(null, new Integer(1));
      fail();
    } catch (NullPointerException expected) {
    }
    map.putInstance(Integer.class, null);
    assertNull(map.get(Integer.class));

            

Reported by PMD.

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

Line: 37

               * @author Kevin Bourrillion
 */
public class MutableClassToInstanceMapTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(MutableClassToInstanceMapTest.class);

    suite.addTest(
        MapTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 52

                                  MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
                    for (Object object : elements) {
                      Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
                      map.putInstance(entry.getKey(), entry.getValue());
                    }
                    return (Map) map;
                  }
                })
            .named("MutableClassToInstanceMap")

            

Reported by PMD.

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

Line: 52

                                  MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
                    for (Object object : elements) {
                      Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
                      map.putInstance(entry.getKey(), entry.getValue());
                    }
                    return (Map) map;
                  }
                })
            .named("MutableClassToInstanceMap")

            

Reported by PMD.

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

Line: 71

                  return suite;
  }

  private ClassToInstanceMap<Number> map;

  @Override
  protected void setUp() throws Exception {
    map = MutableClassToInstanceMap.create();
  }

            

Reported by PMD.

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

Line: 73

              
  private ClassToInstanceMap<Number> map;

  @Override
  protected void setUp() throws Exception {
    map = MutableClassToInstanceMap.create();
  }

  public void testConstraint() {

            

Reported by PMD.

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

Line: 35

               */
public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */

            

Reported by PMD.

Private field 'baos' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 35

               */
public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */

            

Reported by PMD.

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

Line: 36

              public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});

            

Reported by PMD.

Private field 'out' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 36

              public class LittleEndianDataOutputStreamTest extends TestCase {

  private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});

            

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

                private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});
    out.writeBoolean(true);
    out.writeBoolean(false);

            

Reported by PMD.

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

Line: 38

                private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);

  public void testWriteLittleEndian() throws IOException {

    /* Write out various test values in LITTLE ENDIAN FORMAT */
    out.write(new byte[] {-100, 100});
    out.writeBoolean(true);
    out.writeBoolean(false);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  /* Read in various values NORMALLY */
    byte[] b = new byte[2];
    in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 65

                  byte[] b = new byte[2];
    in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());

            

Reported by PMD.

Use assertTrue(x)/assertFalse(x) instead of assertEquals(true, x)/assertEquals(false, x) or assertEquals(Boolean.TRUE, x)/assertEquals(Boolean.FALSE, x).
Design

Line: 66

                  in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());
    assertEquals('\u6100', in.readChar());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 66

                  in.readFully(b);
    assertEquals(-100, b[0]);
    assertEquals(100, b[1]);
    assertEquals(true, in.readBoolean());
    assertEquals(false, in.readBoolean());
    assertEquals(100, in.readByte());
    assertEquals(-100, in.readByte());
    assertEquals(200, in.readUnsignedByte());
    assertEquals('\u6100', in.readChar());

            

Reported by PMD.

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

Line: 104

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class AbstractScheduledService implements Service {
  private static final Logger logger = Logger.getLogger(AbstractScheduledService.class.getName());

  /**
   * A scheduler defines the policy for how the {@link AbstractScheduledService} should run its
   * task.

            

Reported by PMD.

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

Line: 202

                }

  /* use AbstractService for state management */
  private final AbstractService delegate = new ServiceDelegate();

  @WeakOuter
  private final class ServiceDelegate extends AbstractService {

    // A handle to the running task so that we can stop it when a shutdown has been requested.

            

Reported by PMD.

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

Line: 209

              
    // A handle to the running task so that we can stop it when a shutdown has been requested.
    // These two fields are volatile because their values will be accessed from multiple threads.
    @CheckForNull private volatile Cancellable runningTask;
    @CheckForNull private volatile ScheduledExecutorService executorService;

    // This lock protects the task so we can ensure that none of the template methods (startUp,
    // shutDown or runOneIteration) run concurrently with one another.
    // TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the

            

Reported by PMD.

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

Line: 210

                  // A handle to the running task so that we can stop it when a shutdown has been requested.
    // These two fields are volatile because their values will be accessed from multiple threads.
    @CheckForNull private volatile Cancellable runningTask;
    @CheckForNull private volatile ScheduledExecutorService executorService;

    // This lock protects the task so we can ensure that none of the template methods (startUp,
    // shutDown or runOneIteration) run concurrently with one another.
    // TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the
    // lock.

            

Reported by PMD.

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

Line: 216

                  // shutDown or runOneIteration) run concurrently with one another.
    // TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the
    // lock.
    private final ReentrantLock lock = new ReentrantLock();

    @WeakOuter
    class Task implements Runnable {
      @Override
      public void run() {

            

Reported by PMD.

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

Line: 228

                         * requireNonNull is safe because Task isn't run (or at least it doesn't succeed in taking
           * the lock) until after it's scheduled and the runningTask field is set.
           */
          if (requireNonNull(runningTask).isCancelled()) {
            // task may have been cancelled while blocked on the lock.
            return;
          }
          AbstractScheduledService.this.runOneIteration();
        } catch (Throwable t) {

            

Reported by PMD.

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

Line: 232

                          // task may have been cancelled while blocked on the lock.
            return;
          }
          AbstractScheduledService.this.runOneIteration();
        } catch (Throwable t) {
          try {
            shutDown();
          } catch (Exception ignored) {
            logger.log(

            

Reported by PMD.

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

Line: 232

                          // task may have been cancelled while blocked on the lock.
            return;
          }
          AbstractScheduledService.this.runOneIteration();
        } catch (Throwable t) {
          try {
            shutDown();
          } catch (Exception ignored) {
            logger.log(

            

Reported by PMD.

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

Line: 233

                          return;
          }
          AbstractScheduledService.this.runOneIteration();
        } catch (Throwable t) {
          try {
            shutDown();
          } catch (Exception ignored) {
            logger.log(
                Level.WARNING,

            

Reported by PMD.

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

Line: 236

                      } catch (Throwable t) {
          try {
            shutDown();
          } catch (Exception ignored) {
            logger.log(
                Level.WARNING,
                "Error while attempting to shut down the service after failure.",
                ignored);
          }

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/AtomicLongMapBasherTest.java
41 issues
The class 'AtomicLongMapBasherTest' has a Standard Cyclomatic Complexity of 17 (Highest = 16).
Design

Line: 35

               */
@GwtIncompatible // threads

public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;

            

Reported by PMD.

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

Line: 36

              @GwtIncompatible // threads

public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;

            

Reported by PMD.

The method 'testModify_basher()' has a NCSS line count of 65.
Design

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

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

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

The method 'testModify_basher' has a Standard Cyclomatic Complexity of 16.
Design

Line: 38

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

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

              public class AtomicLongMapBasherTest extends TestCase {
  private final Random random = new Random(301);

  public void testModify_basher() throws InterruptedException {
    int nTasks = 3000;
    int nThreads = 100;
    final int getsPerTask = 1000;
    final int deltaRange = 10000;
    final String key = "key";

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

                    @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
      Future<?> possiblyIgnoredError =
          threadPool.submit(
              new Runnable() {
                @Override
                public void run() {
                  int threadSum = 0;
                  for (int j = 0; j < getsPerTask; j++) {
                    long delta = random.nextInt(deltaRange);

            

Reported by PMD.

The method 'run' has a Standard Cyclomatic Complexity of 14.
Design

Line: 55

                        threadPool.submit(
              new Runnable() {
                @Override
                public void run() {
                  int threadSum = 0;
                  for (int j = 0; j < getsPerTask; j++) {
                    long delta = random.nextInt(deltaRange);
                    int behavior = random.nextInt(10);
                    switch (behavior) {

            

Reported by PMD.

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

Line: 114

                            });
    }

    threadPool.shutdown();
    assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

    assertEquals(sum.get(), map.get(key));
  }
}

            

Reported by PMD.

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

Line: 115

                  }

    threadPool.shutdown();
    assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

    assertEquals(sum.get(), map.get(key));
  }
}

            

Reported by PMD.