The following issues were found

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

Line: 15

               * the License.
 */

package com.google.common.net;

import static com.google.common.base.CharMatcher.ascii;
import static com.google.common.base.CharMatcher.javaIsoControl;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkArgument;

            

Reported by PMD.

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

Line: 79

              @GwtCompatible
@Immutable
@ElementTypesAreNonnullByDefault
public final class MediaType {
  private static final String CHARSET_ATTRIBUTE = "charset";
  private static final ImmutableListMultimap<String, String> UTF_8_CONSTANT_PARAMETERS =
      ImmutableListMultimap.of(CHARSET_ATTRIBUTE, Ascii.toLowerCase(UTF_8.name()));

  /** Matcher for type, subtype and attributes. */

            

Reported by PMD.

Avoid really long classes.
Design

Line: 79

              @GwtCompatible
@Immutable
@ElementTypesAreNonnullByDefault
public final class MediaType {
  private static final String CHARSET_ATTRIBUTE = "charset";
  private static final ImmutableListMultimap<String, String> UTF_8_CONSTANT_PARAMETERS =
      ImmutableListMultimap.of(CHARSET_ATTRIBUTE, Ascii.toLowerCase(UTF_8.name()));

  /** Matcher for type, subtype and attributes. */

            

Reported by PMD.

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

Line: 763

                 */
  public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;


            

Reported by PMD.

Field type has the same name as a method
Error

Line: 763

                 */
  public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;


            

Reported by PMD.

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

Line: 764

                public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;

  @LazyInit private int hashCode;

            

Reported by PMD.

Field subtype has the same name as a method
Error

Line: 764

                public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;

  @LazyInit private int hashCode;

            

Reported by PMD.

Field parameters has the same name as a method
Error

Line: 765

              
  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;

  @LazyInit private int hashCode;


            

Reported by PMD.

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

Line: 765

              
  private final String type;
  private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;

  @LazyInit private int hashCode;


            

Reported by PMD.

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

Line: 767

                private final String subtype;
  private final ImmutableListMultimap<String, String> parameters;

  @LazyInit @CheckForNull private String toString;

  @LazyInit private int hashCode;

  @LazyInit @CheckForNull private Optional<Charset> parsedCharset;


            

Reported by PMD.

android/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.

android/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/io/SourceSinkFactories.java
39 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 289

                  public ByteSource createSource(byte[] bytes) throws IOException {
      checkNotNull(bytes);
      File file = createFile();
      OutputStream out = new FileOutputStream(file);
      try {
        out.write(bytes);
      } finally {
        out.close();
      }

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 316

                  public ByteSink createSink() throws IOException {
      File file = createFile();
      if (initialBytes != null) {
        FileOutputStream out = new FileOutputStream(file);
        try {
          out.write(initialBytes);
        } finally {
          out.close();
        }

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 342

                  @Override
    public byte[] getSinkContents() throws IOException {
      File file = getFile();
      InputStream in = new FileInputStream(file);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      byte[] buffer = new byte[100];
      int read;
      while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 359

                  public CharSource createSource(String string) throws IOException {
      checkNotNull(string);
      File file = createFile();
      Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
      try {
        writer.write(string);
      } finally {
        writer.close();
      }

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 386

                  public CharSink createSink() throws IOException {
      File file = createFile();
      if (initialString != null) {
        Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
        try {
          writer.write(initialString);
        } finally {
          writer.close();
        }

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 406

                  @Override
    public String getSinkContents() throws IOException {
      File file = getFile();
      Reader reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
      StringBuilder builder = new StringBuilder();
      CharBuffer buffer = CharBuffer.allocate(100);
      while (reader.read(buffer) != -1) {
        buffer.flip();
        builder.append(buffer);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 277

              
    public final void tearDown() throws IOException {
      if (!fileThreadLocal.get().delete()) {
        logger.warning("Unable to delete file: " + fileThreadLocal.get());
      }
      fileThreadLocal.remove();
    }
  }


            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.io;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.io.SourceSinkFactory.ByteSinkFactory;
import static com.google.common.io.SourceSinkFactory.ByteSourceFactory;
import static com.google.common.io.SourceSinkFactory.CharSinkFactory;

            

Reported by PMD.

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

Line: 47

               *
 * @author Colin Decker
 */
public class SourceSinkFactories {

  private SourceSinkFactories() {}

  public static CharSourceFactory stringCharSourceFactory() {
    return new StringSourceFactory();

            

Reported by PMD.

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

Line: 77

              
  public static ByteSinkFactory appendingFileByteSinkFactory() {
    String initialString = IoTestCase.ASCII + IoTestCase.I18N;
    return new FileByteSinkFactory(initialString.getBytes(Charsets.UTF_8));
  }

  public static CharSourceFactory fileCharSourceFactory() {
    return new FileCharSourceFactory();
  }

            

Reported by PMD.

android/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 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 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.

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.

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.

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.

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.

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.

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

Line: 42

               * @author Colin Decker
 */
@AndroidIncompatible // Android doesn't understand tests that lack default constructors.
public class CharSourceTester extends SourceSinkTester<CharSource, String, CharSourceFactory> {

  private static final ImmutableList<Method> testMethods = getTestMethods(CharSourceTester.class);

  static TestSuite tests(String name, CharSourceFactory factory, boolean testAsByteSource) {
    TestSuite suite = new TestSuite(name);

            

Reported by PMD.

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

Line: 52

                    if (testAsByteSource) {
        suite.addTest(
            suiteForBytes(
                factory, entry.getValue().getBytes(Charsets.UTF_8), name, entry.getKey(), true));
      } else {
        suite.addTest(suiteForString(factory, entry.getValue(), name, entry.getKey()));
      }
    }
    return suite;

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 74

                    CharSourceFactory factory, String string, String name, String desc) {
    TestSuite suite = new TestSuite(name + " [" + desc + "]");
    for (Method method : testMethods) {
      suite.addTest(new CharSourceTester(factory, string, name, desc, method));
    }
    return suite;
  }

  private final ImmutableList<String> expectedLines;

            

Reported by PMD.

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

Line: 79

                  return suite;
  }

  private final ImmutableList<String> expectedLines;

  private CharSource source;

  public CharSourceTester(
      CharSourceFactory factory, String string, String suiteName, String caseDesc, Method method) {

            

Reported by PMD.

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

Line: 81

              
  private final ImmutableList<String> expectedLines;

  private CharSource source;

  public CharSourceTester(
      CharSourceFactory factory, String string, String suiteName, String caseDesc, Method method) {
    super(factory, string, suiteName, caseDesc, method);
    this.expectedLines = getLines(expected);

            

Reported by PMD.

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

Line: 89

                  this.expectedLines = getLines(expected);
  }

  @Override
  protected void setUp() throws Exception {
    this.source = factory.createSource(data);
  }

  public void testOpenStream() 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: 94

                  this.source = factory.createSource(data);
  }

  public void testOpenStream() throws IOException {
    Reader reader = source.openStream();

    StringWriter writer = new StringWriter();
    char[] buf = new char[64];
    int read;

            

Reported by PMD.

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

Line: 95

                }

  public void testOpenStream() throws IOException {
    Reader reader = source.openStream();

    StringWriter writer = new StringWriter();
    char[] buf = new char[64];
    int read;
    while ((read = reader.read(buf)) != -1) {

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 100

                  StringWriter writer = new StringWriter();
    char[] buf = new char[64];
    int read;
    while ((read = reader.read(buf)) != -1) {
      writer.write(buf, 0, read);
    }
    reader.close();
    writer.close();


            

Reported by PMD.

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

Line: 100

                  StringWriter writer = new StringWriter();
    char[] buf = new char[64];
    int read;
    while ((read = reader.read(buf)) != -1) {
      writer.write(buf, 0, read);
    }
    reader.close();
    writer.close();


            

Reported by PMD.

android/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.

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.

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.

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.

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.

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.

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.

android/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 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 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: 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.

android/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-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.