The following issues were found

android/guava-testlib/test/com/google/common/testing/SerializableTesterTest.java
18 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: 29

               * @author Nick Kralevich
 */
public class SerializableTesterTest extends TestCase {
  public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

            

Reported by PMD.

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

Line: 29

               * @author Nick Kralevich
 */
public class SerializableTesterTest extends TestCase {
  public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

                public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                  String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;

            

Reported by PMD.

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

Line: 36

                  assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);
      errorNotThrown = true;

            

Reported by PMD.

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

Line: 36

                  assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);
      errorNotThrown = true;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                    // expected
      assertContains("must be Object#equals to", error.getMessage());
    }
    assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();

            

Reported by PMD.

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

Line: 49

                  assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);

            

Reported by PMD.

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

Line: 49

                  assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                    // expected
      assertContains("must be equal to the Object#hashCode", error.getMessage());
    }
    assertFalse(errorNotThrown);
  }

  public void testObjectWhichIsEqualButChangesClass() {
    ObjectWhichIsEqualButChangesClass orig = new ObjectWhichIsEqualButChangesClass();
    boolean errorNotThrown = false;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java
18 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: 45

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    int initialSize = collection.size();
    assertTrue("remove(present) should return true", collection.remove(e0()));
    assertEquals(

            

Reported by PMD.

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

Line: 47

              public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    int initialSize = collection.size();
    assertTrue("remove(present) should return true", collection.remove(e0()));
    assertEquals(
        "remove(present) should decrease a collection's size by one.",
        initialSize - 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: 57

                  expectMissing(e0());
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  @CollectionSize.Require(SEVERAL)
  public void testRemovePresentConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      assertTrue(collection.remove(e0()));

            

Reported by PMD.

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

Line: 70

                  }
  }

  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_notPresent() {
    assertFalse("remove(notPresent) should return false", collection.remove(e3()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 76

                  expectUnchanged();
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();

            

Reported by PMD.

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

Line: 78

              
  @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();
    assertTrue("remove(null) should return true", collection.remove(null));
    assertEquals(

            

Reported by PMD.

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

Line: 79

                @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();
    assertTrue("remove(null) should return true", collection.remove(null));
    assertEquals(
        "remove(present) should decrease a collection's size by one.",

            

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

                  expectMissing((E) null);
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_unsupported() {
    try {
      collection.remove(e0());
      fail("remove(present) should throw UnsupportedOperationException");

            

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

                  assertTrue("remove(present) should not remove the element", collection.contains(e0()));
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  public void testRemove_unsupportedNotPresent() {
    try {
      assertFalse(
          "remove(notPresent) should return false or throw UnsupportedOperationException",
          collection.remove(e3()));

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 108

                    assertFalse(
          "remove(notPresent) should return false or throw UnsupportedOperationException",
          collection.remove(e3()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
    expectMissing(e3());
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/io/IoTestCase.java
18 issues
Avoid throwing raw exception types.
Design

Line: 72

              
    URL testFileUrl = IoTestCase.class.getResource("testdata/i18n.txt");
    if (testFileUrl == null) {
      throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 159

                private static void copy(URL url, File file) throws IOException {
    InputStream in = url.openStream();
    try {
      OutputStream out = new FileOutputStream(file);
      try {
        byte[] buf = new byte[4096];
        for (int read = in.read(buf); read != -1; read = in.read(buf)) {
          out.write(buf, 0, read);
        }

            

Reported by PMD.

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

Line: 50

                    " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

  private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override

            

Reported by PMD.

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

Line: 51

                        + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

  private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {

            

Reported by PMD.

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

Line: 53

                private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {
    for (File file : filesToDelete) {
      if (file.exists()) {

            

Reported by PMD.

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

Line: 55

              
  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {
    for (File file : filesToDelete) {
      if (file.exists()) {
        delete(file);
      }

            

Reported by PMD.

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

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

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

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

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

Line: 79

                    try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException
        // fall back to copying URLs to files in the testDir == null block below
      }
    }


            

Reported by PMD.

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

Line: 39

               * @author Michael Lancaster
 */
public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(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: 41

              public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(false);
    doClose(mockCloseable, false, false);


            

Reported by PMD.

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

Line: 41

              public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(false);
    doClose(mockCloseable, false, false);


            

Reported by PMD.

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

Line: 51

                  doClose(mockCloseable, true, false);
  }

  public void testClose_closeableWithEatenException() throws IOException {
    // make sure that no exception is thrown if 'swallowException' is true
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, true);
  }

            

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

                  doClose(mockCloseable, true, false);
  }

  public void testClose_closeableWithEatenException() throws IOException {
    // make sure that no exception is thrown if 'swallowException' is true
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, true);
  }

            

Reported by PMD.

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

Line: 58

                  doClose(mockCloseable, true);
  }

  public void testClose_closeableWithThrownException() throws IOException {
    // make sure that the exception is thrown if 'swallowException' is false
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, 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: 58

                  doClose(mockCloseable, true);
  }

  public void testClose_closeableWithThrownException() throws IOException {
    // make sure that the exception is thrown if 'swallowException' is false
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, 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: 65

                  doClose(mockCloseable, false);
  }

  public void testCloseQuietly_inputStreamWithEatenException() throws IOException {
    TestInputStream in =
        new TestInputStream(new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                  TestInputStream in =
        new TestInputStream(new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }

  public void testCloseQuietly_readerWithEatenException() throws IOException {
    TestReader in = new TestReader(TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);

            

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

                  assertTrue(in.closed());
  }

  public void testCloseQuietly_readerWithEatenException() throws IOException {
    TestReader in = new TestReader(TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }


            

Reported by PMD.

guava/src/com/google/common/primitives/Ints.java
18 issues
Avoid using a branching statement as the last in a loop.
Error

Line: 190

                        continue outer;
        }
      }
      return i;
    }
    return -1;
  }

  /**

            

Reported by PMD.

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

Line: 50

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Ints extends IntsMethodsForWeb {
  private Ints() {}

  /**
   * The number of bytes required to represent a primitive {@code int} value.
   *

            

Reported by PMD.

Possible God Class (WMC=59, ATFD=33, TCC=0.000%)
Design

Line: 50

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Ints extends IntsMethodsForWeb {
  private Ints() {}

  /**
   * The number of bytes required to represent a primitive {@code int} value.
   *

            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 508

                public static void reverse(int[] array, int fromIndex, int toIndex) {
    checkNotNull(array);
    checkPositionIndexes(fromIndex, toIndex, array.length);
    for (int i = fromIndex, j = toIndex - 1; i < j; i++, j--) {
      int tmp = array[i];
      array[i] = array[j];
      array[j] = tmp;
    }
  }

            

Reported by PMD.

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

Line: 568

                @GwtCompatible
  private static class IntArrayAsList extends AbstractList<Integer>
      implements RandomAccess, Serializable {
    final int[] array;
    final int start;
    final int end;

    IntArrayAsList(int[] array) {
      this(array, 0, array.length);

            

Reported by PMD.

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

Line: 569

                private static class IntArrayAsList extends AbstractList<Integer>
      implements RandomAccess, Serializable {
    final int[] array;
    final int start;
    final int end;

    IntArrayAsList(int[] array) {
      this(array, 0, array.length);
    }

            

Reported by PMD.

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

Line: 570

                    implements RandomAccess, Serializable {
    final int[] array;
    final int start;
    final int end;

    IntArrayAsList(int[] array) {
      this(array, 0, array.length);
    }


            

Reported by PMD.

The user-supplied array 'array' is stored directly.
Design

Line: 576

                    this(array, 0, array.length);
    }

    IntArrayAsList(int[] array, int start, int end) {
      this.array = array;
      this.start = start;
      this.end = end;
    }


            

Reported by PMD.

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

Line: 660

                    if (object instanceof IntArrayAsList) {
        IntArrayAsList that = (IntArrayAsList) object;
        int size = size();
        if (that.size() != size) {
          return false;
        }
        for (int i = 0; i < size; i++) {
          if (array[start + i] != that.array[that.start + i]) {
            return false;

            

Reported by PMD.

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

Line: 746

                @CheckForNull
  public static Integer tryParse(String string, int radix) {
    Long result = Longs.tryParse(string, radix);
    if (result == null || result.longValue() != result.intValue()) {
      return null;
    } else {
      return result.intValue();
    }
  }

            

Reported by PMD.

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

Line: 46

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class ForwardingDeque<E extends @Nullable Object> extends ForwardingQueue<E>
    implements Deque<E> {

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

  @Override

            

Reported by PMD.

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

Line: 56

              
  @Override
  public void addFirst(@ParametricNullness E e) {
    delegate().addFirst(e);
  }

  @Override
  public void addLast(@ParametricNullness E e) {
    delegate().addLast(e);

            

Reported by PMD.

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

Line: 61

              
  @Override
  public void addLast(@ParametricNullness E e) {
    delegate().addLast(e);
  }

  @Override
  public Iterator<E> descendingIterator() {
    return delegate().descendingIterator();

            

Reported by PMD.

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

Line: 66

              
  @Override
  public Iterator<E> descendingIterator() {
    return delegate().descendingIterator();
  }

  @Override
  @ParametricNullness
  public E getFirst() {

            

Reported by PMD.

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

Line: 72

                @Override
  @ParametricNullness
  public E getFirst() {
    return delegate().getFirst();
  }

  @Override
  @ParametricNullness
  public E getLast() {

            

Reported by PMD.

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

Line: 78

                @Override
  @ParametricNullness
  public E getLast() {
    return delegate().getLast();
  }

  @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this?
  @Override
  public boolean offerFirst(@ParametricNullness E e) {

            

Reported by PMD.

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

Line: 84

                @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this?
  @Override
  public boolean offerFirst(@ParametricNullness E e) {
    return delegate().offerFirst(e);
  }

  @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this?
  @Override
  public boolean offerLast(@ParametricNullness E e) {

            

Reported by PMD.

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

Line: 90

                @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this?
  @Override
  public boolean offerLast(@ParametricNullness E e) {
    return delegate().offerLast(e);
  }

  @Override
  @CheckForNull
  public E peekFirst() {

            

Reported by PMD.

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

Line: 96

                @Override
  @CheckForNull
  public E peekFirst() {
    return delegate().peekFirst();
  }

  @Override
  @CheckForNull
  public E peekLast() {

            

Reported by PMD.

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

Line: 102

                @Override
  @CheckForNull
  public E peekLast() {
    return delegate().peekLast();
  }

  @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this?
  @Override
  @CheckForNull

            

Reported by PMD.

guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java
18 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 40

                private static final ImmutableList<String> LIST1 = ImmutableList.of("one", "two");
  private static final ImmutableList<String> LIST2 = ImmutableList.of("three");

  public void testDelegate() {
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingList(LIST1)));
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingListWithEquals(LIST1)));
  }

  public void testToString() {

            

Reported by PMD.

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

Line: 40

                private static final ImmutableList<String> LIST1 = ImmutableList.of("one", "two");
  private static final ImmutableList<String> LIST2 = ImmutableList.of("three");

  public void testDelegate() {
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingList(LIST1)));
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingListWithEquals(LIST1)));
  }

  public void testToString() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 41

                private static final ImmutableList<String> LIST2 = ImmutableList.of("three");

  public void testDelegate() {
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingList(LIST1)));
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingListWithEquals(LIST1)));
  }

  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

              
  public void testDelegate() {
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingList(LIST1)));
    assertEquals(LIST1, ImmutableList.copyOf(newDelegatingListWithEquals(LIST1)));
  }

  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);
    assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString());

            

Reported by PMD.

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

Line: 45

                  assertEquals(LIST1, ImmutableList.copyOf(newDelegatingListWithEquals(LIST1)));
  }

  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);
    assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString());
  }

  interface A {}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

              
  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);
    assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString());
  }

  interface A {}

  interface B {}

            

Reported by PMD.

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

Line: 47

              
  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);
    assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString());
  }

  interface A {}

  interface B {}

            

Reported by PMD.

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

Line: 47

              
  public void testToString() {
    List<String> proxy = newDelegatingList(LIST1);
    assertEquals(Proxy.getInvocationHandler(proxy).toString(), proxy.toString());
  }

  interface A {}

  interface B {}

            

Reported by PMD.

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

Line: 54

              
  interface B {}

  public void testEquals() {
    class AB implements A, B {}
    class BA implements B, A {}
    AB ab = new AB();
    BA ba = new BA();
    new EqualsTester()

            

Reported by PMD.

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

Line: 54

              
  interface B {}

  public void testEquals() {
    class AB implements A, B {}
    class BA implements B, A {}
    AB ab = new AB();
    BA ba = new BA();
    new EqualsTester()

            

Reported by PMD.

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

Line: 47

               * @param <V> Value parameter type
 */
@ElementTypesAreNonnullByDefault
class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

            

Reported by PMD.

Field isDirected has the same name as a method
Error

Line: 48

               */
@ElementTypesAreNonnullByDefault
class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;


            

Reported by PMD.

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

Line: 48

               */
@ElementTypesAreNonnullByDefault
class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;


            

Reported by PMD.

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

Line: 49

              @ElementTypesAreNonnullByDefault
class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed

            

Reported by PMD.

Field allowsSelfLoops has the same name as a method
Error

Line: 49

              @ElementTypesAreNonnullByDefault
class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed

            

Reported by PMD.

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

Line: 50

              class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed


            

Reported by PMD.

Field nodeOrder has the same name as a method
Error

Line: 50

              class StandardValueGraph<N, V> extends AbstractValueGraph<N, V> {
  private final boolean isDirected;
  private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed


            

Reported by PMD.

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

Line: 52

                private final boolean allowsSelfLoops;
  private final ElementOrder<N> nodeOrder;

  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed

  /** Constructs a graph with the properties specified in {@code builder}. */
  StandardValueGraph(AbstractGraphBuilder<? super N> builder) {

            

Reported by PMD.

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

Line: 54

              
  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed

  /** Constructs a graph with the properties specified in {@code builder}. */
  StandardValueGraph(AbstractGraphBuilder<? super N> builder) {
    this(
        builder,

            

Reported by PMD.

Field edgeCount has the same name as a method
Error

Line: 54

              
  final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;

  long edgeCount; // must be updated when edges are added or removed

  /** Constructs a graph with the properties specified in {@code builder}. */
  StandardValueGraph(AbstractGraphBuilder<? super N> builder) {
    this(
        builder,

            

Reported by PMD.

guava/src/com/google/common/base/Joiner.java
18 issues
This class has too many methods, consider refactoring it.
Design

Line: 69

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public class Joiner {
  /** Returns a joiner which automatically places {@code separator} between consecutive elements. */
  public static Joiner on(String separator) {
    return new Joiner(separator);
  }


            

Reported by PMD.

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

Line: 80

                  return new Joiner(String.valueOf(separator));
  }

  private final String separator;

  private Joiner(String separator) {
    this.separator = checkNotNull(separator);
  }


            

Reported by PMD.

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

Line: 244

                  return new Joiner(this) {
      @Override
      CharSequence toString(@CheckForNull Object part) {
        return (part == null) ? nullText : Joiner.this.toString(part);
      }

      @Override
      public Joiner useForNull(String nullText) {
        throw new UnsupportedOperationException("already specified useForNull");

            

Reported by PMD.

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

Line: 244

                  return new Joiner(this) {
      @Override
      CharSequence toString(@CheckForNull Object part) {
        return (part == null) ? nullText : Joiner.this.toString(part);
      }

      @Override
      public Joiner useForNull(String nullText) {
        throw new UnsupportedOperationException("already specified useForNull");

            

Reported by PMD.

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

Line: 273

                      while (parts.hasNext()) {
          Object part = parts.next();
          if (part != null) {
            appendable.append(Joiner.this.toString(part));
            break;
          }
        }
        while (parts.hasNext()) {
          Object part = parts.next();

            

Reported by PMD.

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

Line: 273

                      while (parts.hasNext()) {
          Object part = parts.next();
          if (part != null) {
            appendable.append(Joiner.this.toString(part));
            break;
          }
        }
        while (parts.hasNext()) {
          Object part = parts.next();

            

Reported by PMD.

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

Line: 281

                        Object part = parts.next();
          if (part != null) {
            appendable.append(separator);
            appendable.append(Joiner.this.toString(part));
          }
        }
        return appendable;
      }


            

Reported by PMD.

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

Line: 281

                        Object part = parts.next();
          if (part != null) {
            appendable.append(separator);
            appendable.append(Joiner.this.toString(part));
          }
        }
        return appendable;
      }


            

Reported by PMD.

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

Line: 336

                 * @since 2.0
   */
  public static final class MapJoiner {
    private final Joiner joiner;
    private final String keyValueSeparator;

    private MapJoiner(Joiner joiner, String keyValueSeparator) {
      this.joiner = joiner; // only "this" is ever passed, so don't checkNotNull
      this.keyValueSeparator = checkNotNull(keyValueSeparator);

            

Reported by PMD.

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

Line: 337

                 */
  public static final class MapJoiner {
    private final Joiner joiner;
    private final String keyValueSeparator;

    private MapJoiner(Joiner joiner, String keyValueSeparator) {
      this.joiner = joiner; // only "this" is ever passed, so don't checkNotNull
      this.keyValueSeparator = checkNotNull(keyValueSeparator);
    }

            

Reported by PMD.

guava/src/com/google/common/eventbus/Dispatcher.java
18 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 79

                  // This dispatcher matches the original dispatch behavior of EventBus.

    /** Per-thread queue of events to dispatch. */
    private final ThreadLocal<Queue<Event>> queue =
        new ThreadLocal<Queue<Event>>() {
          @Override
          protected Queue<Event> initialValue() {
            return Queues.newArrayDeque();
          }

            

Reported by PMD.

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

Line: 88

                      };

    /** Per-thread dispatch state, used to avoid reentrant event dispatching. */
    private final ThreadLocal<Boolean> dispatching =
        new ThreadLocal<Boolean>() {
          @Override
          protected Boolean initialValue() {
            return false;
          }

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 107

                      dispatching.set(true);
        try {
          Event nextEvent;
          while ((nextEvent = queueForThread.poll()) != null) {
            while (nextEvent.subscribers.hasNext()) {
              nextEvent.subscribers.next().dispatchEvent(nextEvent.event);
            }
          }
        } finally {

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 108

                      try {
          Event nextEvent;
          while ((nextEvent = queueForThread.poll()) != null) {
            while (nextEvent.subscribers.hasNext()) {
              nextEvent.subscribers.next().dispatchEvent(nextEvent.event);
            }
          }
        } finally {
          dispatching.remove();

            

Reported by PMD.

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

Line: 109

                        Event nextEvent;
          while ((nextEvent = queueForThread.poll()) != null) {
            while (nextEvent.subscribers.hasNext()) {
              nextEvent.subscribers.next().dispatchEvent(nextEvent.event);
            }
          }
        } finally {
          dispatching.remove();
          queue.remove();

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 109

                        Event nextEvent;
          while ((nextEvent = queueForThread.poll()) != null) {
            while (nextEvent.subscribers.hasNext()) {
              nextEvent.subscribers.next().dispatchEvent(nextEvent.event);
            }
          }
        } finally {
          dispatching.remove();
          queue.remove();

            

Reported by PMD.

It is somewhat confusing to have a field name matching the declaring class name
Error

Line: 120

                  }

    private static final class Event {
      private final Object event;
      private final Iterator<Subscriber> subscribers;

      private Event(Object event, Iterator<Subscriber> subscribers) {
        this.event = event;
        this.subscribers = subscribers;

            

Reported by PMD.

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

Line: 120

                  }

    private static final class Event {
      private final Object event;
      private final Iterator<Subscriber> subscribers;

      private Event(Object event, Iterator<Subscriber> subscribers) {
        this.event = event;
        this.subscribers = subscribers;

            

Reported by PMD.

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

Line: 121

              
    private static final class Event {
      private final Object event;
      private final Iterator<Subscriber> subscribers;

      private Event(Object event, Iterator<Subscriber> subscribers) {
        this.event = event;
        this.subscribers = subscribers;
      }

            

Reported by PMD.

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

Line: 152

                  // in some cases.

    /** Global event queue. */
    private final ConcurrentLinkedQueue<EventWithSubscriber> queue =
        Queues.newConcurrentLinkedQueue();

    @Override
    void dispatch(Object event, Iterator<Subscriber> subscribers) {
      checkNotNull(event);

            

Reported by PMD.