The following issues were found

guava-tests/benchmark/com/google/common/io/ByteSourceAsCharSourceReadBenchmark.java
23 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 66

                        // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions
          int maxChars = (int) (size.get().intValue() * cs.newDecoder().maxCharsPerByte());
          char[] buffer = new char[maxChars];
          int bufIndex = 0;
          int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;

            

Reported by PMD.

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

Line: 66

                        // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions
          int maxChars = (int) (size.get().intValue() * cs.newDecoder().maxCharsPerByte());
          char[] buffer = new char[maxChars];
          int bufIndex = 0;
          int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 72

                        int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;
            while (remaining > 0 && (nRead = reader.read(buffer, bufIndex, remaining)) != -1) {
              bufIndex += nRead;
              remaining -= nRead;
            }
            if (nRead == -1) {
              // we reached EOF

            

Reported by PMD.

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

Line: 86

                          // Fallback to an incremental approach
            StringBuilder builder = new StringBuilder(bufIndex + 32);
            builder.append(buffer, 0, bufIndex);
            buffer = null; // release for gc
            CharStreams.copy(reader, builder);
            return builder.toString();
          }

        } else {

            

Reported by PMD.

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

Line: 101

                }

  @Param({"UTF-8"})
  String charsetName;

  @Param ReadStrategy strategy;

  @Param({"10", "1024", "1048576"})
  int size;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ConcurrentMapPutIfAbsentTester.java
23 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: 47

                  return (ConcurrentMap<K, V>) super.getMap();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutIfAbsent_supportedAbsent() {
    assertNull("putIfAbsent(notPresent, value) should return null", putIfAbsent(e3()));
    expectAdded(e3());
  }


            

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

                  expectAdded(e3());
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_supportedPresent() {
    assertEquals(
        "putIfAbsent(present, value) should return existing value",
        v0(),

            

Reported by PMD.

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

Line: 59

                  assertEquals(
        "putIfAbsent(present, value) should return existing value",
        v0(),
        getMap().putIfAbsent(k0(), v3()));
    expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  public void testPutIfAbsent_unsupportedAbsent() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  public void testPutIfAbsent_unsupportedAbsent() {
    try {
      putIfAbsent(e3());
      fail("putIfAbsent(notPresent, value) should throw");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

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

Line: 74

                  expectMissing(e3());
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_unsupportedPresentExistingValue() {
    try {
      assertEquals(
          "putIfAbsent(present, existingValue) should return present or throw",

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 82

                        "putIfAbsent(present, existingValue) should return present or throw",
          v0(),
          putIfAbsent(e0()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_unsupportedPresentDifferentValue() {
    try {
      getMap().putIfAbsent(k0(), v3());
    } catch (UnsupportedOperationException tolerated) {

            

Reported by PMD.

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

Line: 91

                @CollectionSize.Require(absent = ZERO)
  public void testPutIfAbsent_unsupportedPresentDifferentValue() {
    try {
      getMap().putIfAbsent(k0(), v3());
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 92

                public void testPutIfAbsent_unsupportedPresentDifferentValue() {
    try {
      getMap().putIfAbsent(k0(), v3());
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS)

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS)
  public void testPutIfAbsent_nullKeyUnsupported() {
    try {
      getMap().putIfAbsent(null, v3());
      fail("putIfAbsent(null, value) should throw");
    } catch (NullPointerException expected) {

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/base/AsciiBenchmark.java
23 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

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

  @Param({"20", "2000"})
  int size;

  @Param({"2", "20"})
  int nonAlphaRatio; // one non-alpha char per this many chars

  @Param boolean noWorkToDo;

            

Reported by PMD.

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

Line: 42

                int size;

  @Param({"2", "20"})
  int nonAlphaRatio; // one non-alpha char per this many chars

  @Param boolean noWorkToDo;

  Random random;
  String testString;

            

Reported by PMD.

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

Line: 44

                @Param({"2", "20"})
  int nonAlphaRatio; // one non-alpha char per this many chars

  @Param boolean noWorkToDo;

  Random random;
  String testString;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 46

              
  @Param boolean noWorkToDo;

  Random random;
  String testString;

  @BeforeExperiment
  void setUp() {
    random = new Random(0xdeadbeef); // fix the seed so results are comparable across runs

            

Reported by PMD.

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

Line: 47

                @Param boolean noWorkToDo;

  Random random;
  String testString;

  @BeforeExperiment
  void setUp() {
    random = new Random(0xdeadbeef); // fix the seed so results are comparable across runs


            

Reported by PMD.

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

Line: 49

                Random random;
  String testString;

  @BeforeExperiment
  void setUp() {
    random = new Random(0xdeadbeef); // fix the seed so results are comparable across runs

    int nonAlpha = size / nonAlphaRatio;
    int alpha = size - nonAlpha;

            

Reported by PMD.

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

Line: 82

              
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy += Ascii.toUpperCase(string).length();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 93

              
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy += charSequenceToUpperCase(string).length();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 104

              
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy += string.toUpperCase(Locale.US).length();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Error

Line: 112

                @Benchmark
  boolean equalsIgnoreCaseCharSequence(int reps) {
    // This benchmark has no concept of "noWorkToDo".
    String upperString = testString.toUpperCase();
    CharSequence testSeq = new StringBuilder(testString);
    CharSequence upperSeq = new StringBuilder(upperString);
    CharSequence[] lhs = new CharSequence[] {testString, testSeq, testString, testSeq};
    CharSequence[] rhs = new CharSequence[] {upperString, upperString, upperSeq, upperSeq};


            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/io/ByteSourceAsCharSourceReadBenchmark.java
23 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 60

                    String read(ByteSource byteSource, Charset cs) throws IOException {
        Optional<Long> size = byteSource.sizeIfKnown();
        // if we know the size and it fits in an int
        if (size.isPresent() && size.get().longValue() == size.get().intValue()) {
          // otherwise try to presize a StringBuilder
          // it is kind of lame that we need to construct a decoder to access this value.
          // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions

            

Reported by PMD.

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

Line: 66

                        // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions
          int maxChars = (int) (size.get().intValue() * cs.newDecoder().maxCharsPerByte());
          char[] buffer = new char[maxChars];
          int bufIndex = 0;
          int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;

            

Reported by PMD.

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

Line: 66

                        // if this is a concern we could add special cases for some known charsets (like utf8)
          // or we could avoid inputstreamreader and use the decoder api directly
          // TODO(lukes): in a real implementation we would need to handle overflow conditions
          int maxChars = (int) (size.get().intValue() * cs.newDecoder().maxCharsPerByte());
          char[] buffer = new char[maxChars];
          int bufIndex = 0;
          int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 72

                        int remaining = buffer.length;
          try (InputStreamReader reader = new InputStreamReader(byteSource.openStream(), cs)) {
            int nRead = 0;
            while (remaining > 0 && (nRead = reader.read(buffer, bufIndex, remaining)) != -1) {
              bufIndex += nRead;
              remaining -= nRead;
            }
            if (nRead == -1) {
              // we reached EOF

            

Reported by PMD.

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

Line: 86

                          // Fallback to an incremental approach
            StringBuilder builder = new StringBuilder(bufIndex + 32);
            builder.append(buffer, 0, bufIndex);
            buffer = null; // release for gc
            CharStreams.copy(reader, builder);
            return builder.toString();
          }

        } else {

            

Reported by PMD.

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

Line: 101

                }

  @Param({"UTF-8"})
  String charsetName;

  @Param ReadStrategy strategy;

  @Param({"10", "1024", "1048576"})
  int size;

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/util/concurrent/SingleThreadAbstractFutureBenchmark.java
23 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

              /** A benchmark that times how long it takes to add a given number of */
@VmOptions({"-Xms8g", "-Xmx8g"})
public class SingleThreadAbstractFutureBenchmark {
  @Param Impl impl;

  private final Exception exception = new Exception();
  private Facade<?> notDoneFuture;

  @BeforeExperiment

            

Reported by PMD.

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

Line: 37

              public class SingleThreadAbstractFutureBenchmark {
  @Param Impl impl;

  private final Exception exception = new Exception();
  private Facade<?> notDoneFuture;

  @BeforeExperiment
  void setUp() throws Exception {
    notDoneFuture = impl.newFacade();

            

Reported by PMD.

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

Line: 38

                @Param Impl impl;

  private final Exception exception = new Exception();
  private Facade<?> notDoneFuture;

  @BeforeExperiment
  void setUp() throws Exception {
    notDoneFuture = impl.newFacade();
  }

            

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 final Exception exception = new Exception();
  private Facade<?> notDoneFuture;

  @BeforeExperiment
  void setUp() throws Exception {
    notDoneFuture = impl.newFacade();
  }

  @Benchmark

            

Reported by PMD.

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

Line: 41

                private Facade<?> notDoneFuture;

  @BeforeExperiment
  void setUp() throws Exception {
    notDoneFuture = impl.newFacade();
  }

  @Benchmark
  public long timeComplete_Normal(int reps) throws Exception {

            

Reported by PMD.

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

Line: 46

                }

  @Benchmark
  public long timeComplete_Normal(int reps) throws Exception {
    long r = 0;
    List<Facade<Integer>> list = new ArrayList<>(reps);
    for (int i = 0; i < reps; i++) {
      final Facade<Integer> localFuture = impl.newFacade();
      list.add(localFuture);

            

Reported by PMD.

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

Line: 52

                  for (int i = 0; i < reps; i++) {
      final Facade<Integer> localFuture = impl.newFacade();
      list.add(localFuture);
      localFuture.set(i);
    }
    for (int i = 0; i < reps; i++) {
      r += list.get(i).get();
    }
    return r;

            

Reported by PMD.

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

Line: 55

                    localFuture.set(i);
    }
    for (int i = 0; i < reps; i++) {
      r += list.get(i).get();
    }
    return r;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 61

                }

  @Benchmark
  public long timeComplete_Failure(int reps) throws Exception {
    long r = 0;
    List<Facade<Integer>> list = new ArrayList<>(reps);
    for (int i = 0; i < reps; i++) {
      final Facade<Integer> localFuture = impl.newFacade();
      list.add(localFuture);

            

Reported by PMD.

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

Line: 67

                  for (int i = 0; i < reps; i++) {
      final Facade<Integer> localFuture = impl.newFacade();
      list.add(localFuture);
      localFuture.setException(exception);
    }
    for (int i = 0; i < reps; i++) {
      Facade<Integer> facade = list.get(i);
      try {
        facade.get();

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ConcurrentMapRemoveTester.java
23 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

                  return (ConcurrentMap<K, V>) super.getMap();
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_supportedPresent() {
    assertTrue(getMap().remove(k0(), v0()));
    expectMissing(e0());
  }

            

Reported by PMD.

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

Line: 48

                @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_supportedPresent() {
    assertTrue(getMap().remove(k0(), v0()));
    expectMissing(e0());
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedPresentKeyWrongValue() {

            

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

                  expectMissing(e0());
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedPresentKeyWrongValue() {
    assertFalse(getMap().remove(k0(), v3()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 54

              
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedPresentKeyWrongValue() {
    assertFalse(getMap().remove(k0(), v3()));
    expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedWrongKeyPresentValue() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedWrongKeyPresentValue() {
    assertFalse(getMap().remove(k3(), v0()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 60

              
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedWrongKeyPresentValue() {
    assertFalse(getMap().remove(k3(), v0()));
    expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedAbsentKeyAbsentValue() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedAbsentKeyAbsentValue() {
    assertFalse(getMap().remove(k3(), v3()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 66

              
  @MapFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_supportedAbsentKeyAbsentValue() {
    assertFalse(getMap().remove(k3(), v3()));
    expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
  public void testRemove_nullKeyQueriesUnsupported() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
  public void testRemove_nullKeyQueriesUnsupported() {
    try {
      assertFalse(getMap().remove(null, v3()));
    } catch (NullPointerException tolerated) {
      // since the operation would be a no-op, the exception is not required

            

Reported by PMD.

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

Line: 73

                @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
  public void testRemove_nullKeyQueriesUnsupported() {
    try {
      assertFalse(getMap().remove(null, v3()));
    } catch (NullPointerException tolerated) {
      // since the operation would be a no-op, the exception is not required
    }
    expectUnchanged();
  }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java
23 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 77

                @Override
  protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(MultisetNavigationTester.class);
    return testers;
  }

  @Override
  TestSuite createElementSetTestSuite(

            

Reported by PMD.

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

Line: 118

                List<TestSuite> createDerivedSuites(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
    List<TestSuite> derivedSuites = Lists.newArrayList();

    if (!parentBuilder.getFeatures().contains(NoRecurse.DESCENDING)) {
      derivedSuites.add(createDescendingSuite(parentBuilder));
    }

    if (parentBuilder.getFeatures().contains(SERIALIZABLE)) {
      derivedSuites.add(createReserializedSuite(parentBuilder));

            

Reported by PMD.

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

Line: 122

                    derivedSuites.add(createDescendingSuite(parentBuilder));
    }

    if (parentBuilder.getFeatures().contains(SERIALIZABLE)) {
      derivedSuites.add(createReserializedSuite(parentBuilder));
    }

    if (!parentBuilder.getFeatures().contains(NoRecurse.SUBMULTISET)) {
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));

            

Reported by PMD.

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

Line: 126

                    derivedSuites.add(createReserializedSuite(parentBuilder));
    }

    if (!parentBuilder.getFeatures().contains(NoRecurse.SUBMULTISET)) {
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE));
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND));
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE));
      derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE));

            

Reported by PMD.

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

Line: 154

                    features.remove(SERIALIZABLE);
    }

    SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
    final Comparator<? super E> comparator = emptyMultiset.comparator();
    SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

            

Reported by PMD.

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

Line: 155

                  }

    SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
    final Comparator<? super E> comparator = emptyMultiset.comparator();
    SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());


            

Reported by PMD.

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

Line: 156

              
    SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
    final Comparator<? super E> comparator = emptyMultiset.comparator();
    SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

    Collections.sort(samplesList, comparator);

            

Reported by PMD.

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

Line: 159

                  SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

    Collections.sort(samplesList, comparator);
    final E firstInclusive = samplesList.get(0);
    final E lastInclusive = samplesList.get(samplesList.size() - 1);


            

Reported by PMD.

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

Line: 159

                  SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

    Collections.sort(samplesList, comparator);
    final E firstInclusive = samplesList.get(0);
    final E lastInclusive = samplesList.get(samplesList.size() - 1);


            

Reported by PMD.

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

Line: 159

                  SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked")
    List<E> samplesList =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

    Collections.sort(samplesList, comparator);
    final E firstInclusive = samplesList.get(0);
    final E lastInclusive = samplesList.get(samplesList.size() - 1);


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java
23 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.testing;

import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS;


            

Reported by PMD.

High amount of different objects as members denotes a high coupling
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect.testing;

import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS;


            

Reported by PMD.

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

Line: 70

                protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());

    testers.add(CollectionSerializationEqualTester.class);
    testers.add(ListAddAllAtIndexTester.class);
    testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);

            

Reported by PMD.

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

Line: 71

                  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());

    testers.add(CollectionSerializationEqualTester.class);
    testers.add(ListAddAllAtIndexTester.class);
    testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);

            

Reported by PMD.

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

Line: 72

              
    testers.add(CollectionSerializationEqualTester.class);
    testers.add(ListAddAllAtIndexTester.class);
    testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);

            

Reported by PMD.

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

Line: 73

                  testers.add(CollectionSerializationEqualTester.class);
    testers.add(ListAddAllAtIndexTester.class);
    testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);
    testers.add(ListHashCodeTester.class);

            

Reported by PMD.

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

Line: 74

                  testers.add(ListAddAllAtIndexTester.class);
    testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);
    testers.add(ListHashCodeTester.class);
    testers.add(ListIndexOfTester.class);

            

Reported by PMD.

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

Line: 75

                  testers.add(ListAddAllTester.class);
    testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);
    testers.add(ListHashCodeTester.class);
    testers.add(ListIndexOfTester.class);
    testers.add(ListLastIndexOfTester.class);

            

Reported by PMD.

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

Line: 76

                  testers.add(ListAddAtIndexTester.class);
    testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);
    testers.add(ListHashCodeTester.class);
    testers.add(ListIndexOfTester.class);
    testers.add(ListLastIndexOfTester.class);
    testers.add(ListListIteratorTester.class);

            

Reported by PMD.

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

Line: 77

                  testers.add(ListAddTester.class);
    testers.add(ListCreationTester.class);
    testers.add(ListEqualsTester.class);
    testers.add(ListGetTester.class);
    testers.add(ListHashCodeTester.class);
    testers.add(ListIndexOfTester.class);
    testers.add(ListLastIndexOfTester.class);
    testers.add(ListListIteratorTester.class);
    testers.add(ListRemoveAllTester.class);

            

Reported by PMD.

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

Line: 29

               * @author Gregory Kick
 */
@GwtCompatible(emulated = true)
public class EmptyImmutableTableTest extends AbstractImmutableTableTest {
  private static final ImmutableTable<Character, Integer, String> INSTANCE = ImmutableTable.of();

  @Override
  Iterable<ImmutableTable<Character, Integer, String>> getTestInstances() {
    return ImmutableSet.of(INSTANCE);

            

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

                  return ImmutableSet.of(INSTANCE);
  }

  public void testHashCode() {
    assertEquals(0, INSTANCE.hashCode());
  }

  public void testEqualsObject() {
    Table<Character, Integer, String> nonEmptyTable = HashBasedTable.create();

            

Reported by PMD.

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

Line: 41

                  assertEquals(0, INSTANCE.hashCode());
  }

  public void testEqualsObject() {
    Table<Character, Integer, String> nonEmptyTable = HashBasedTable.create();
    nonEmptyTable.put('A', 1, "blah");

    new EqualsTester()
        .addEqualityGroup(INSTANCE, HashBasedTable.create(), TreeBasedTable.create())

            

Reported by PMD.

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

Line: 43

              
  public void testEqualsObject() {
    Table<Character, Integer, String> nonEmptyTable = HashBasedTable.create();
    nonEmptyTable.put('A', 1, "blah");

    new EqualsTester()
        .addEqualityGroup(INSTANCE, HashBasedTable.create(), TreeBasedTable.create())
        .addEqualityGroup(nonEmptyTable)
        .testEquals();

            

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

                      .testEquals();
  }

  @GwtIncompatible // ArrayTable
  public void testEqualsObjectNullValues() {
    new EqualsTester()
        .addEqualityGroup(INSTANCE)
        .addEqualityGroup(ArrayTable.create(ImmutableSet.of('A'), ImmutableSet.of(1)))
        .testEquals();

            

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

                      .testEquals();
  }

  public void testToString() {
    assertEquals("{}", INSTANCE.toString());
  }

  public void testSize() {
    assertEquals(0, INSTANCE.size());

            

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

                  assertEquals("{}", INSTANCE.toString());
  }

  public void testSize() {
    assertEquals(0, INSTANCE.size());
  }

  public void testGet() {
    assertNull(INSTANCE.get('a', 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: 67

                  assertEquals(0, INSTANCE.size());
  }

  public void testGet() {
    assertNull(INSTANCE.get('a', 1));
  }

  public void testIsEmpty() {
    assertTrue(INSTANCE.isEmpty());

            

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

                  assertNull(INSTANCE.get('a', 1));
  }

  public void testIsEmpty() {
    assertTrue(INSTANCE.isEmpty());
  }

  public void testCellSet() {
    assertEquals(ImmutableSet.of(), INSTANCE.cellSet());

            

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

                  assertTrue(INSTANCE.isEmpty());
  }

  public void testCellSet() {
    assertEquals(ImmutableSet.of(), INSTANCE.cellSet());
  }

  public void testColumn() {
    assertEquals(ImmutableMap.of(), INSTANCE.column(1));

            

Reported by PMD.

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

Line: 31

               * @author Chris Nokleberg
 */
public class CountingInputStreamTest extends IoTestCase {
  private CountingInputStream counter;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));

            

Reported by PMD.

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

Line: 33

              public class CountingInputStreamTest extends IoTestCase {
  private CountingInputStream counter;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }


            

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

                  counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }

  public void testReadSingleByte() throws IOException {
    assertEquals(0, counter.getCount());
    assertEquals(0, counter.read());
    assertEquals(1, counter.getCount());
  }


            

Reported by PMD.

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

Line: 39

                  counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }

  public void testReadSingleByte() throws IOException {
    assertEquals(0, counter.getCount());
    assertEquals(0, counter.read());
    assertEquals(1, counter.getCount());
  }


            

Reported by PMD.

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

Line: 45

                  assertEquals(1, counter.getCount());
  }

  public void testReadArray() throws IOException {
    assertEquals(10, counter.read(new byte[10]));
    assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() 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: 45

                  assertEquals(1, counter.getCount());
  }

  public void testReadArray() throws IOException {
    assertEquals(10, counter.read(new byte[10]));
    assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() 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: 50

                  assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {
    assertEquals(3, counter.read(new byte[10], 1, 3));
    assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {

            

Reported by PMD.

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

Line: 50

                  assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {
    assertEquals(3, counter.read(new byte[10], 1, 3));
    assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {

            

Reported by PMD.

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

Line: 55

                  assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {
    assertEquals(10, counter.skip(10));
    assertEquals(10, counter.getCount());
  }

  public void testSkipEOF() 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: 55

                  assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {
    assertEquals(10, counter.skip(10));
    assertEquals(10, counter.getCount());
  }

  public void testSkipEOF() throws IOException {

            

Reported by PMD.