The following issues were found

android/guava/src/com/google/common/collect/ImmutableMultimap.java
35 issues
Avoid throwing null pointer exceptions.
Design

Line: 210

                  @CanIgnoreReturnValue
    public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
      if (key == null) {
        throw new NullPointerException("null key in entry: null=" + Iterables.toString(values));
      }
      Collection<V> valueCollection = builderMap.get(key);
      if (valueCollection != null) {
        for (V value : values) {
          checkEntryNotNull(key, value);

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 720

              
    @GwtIncompatible // not present in emulated superclass
    @Override
    int copyIntoArray(@Nullable Object[] dst, int offset) {
      for (ImmutableCollection<V> valueCollection : multimap.map.values()) {
        offset = valueCollection.copyIntoArray(dst, offset);
      }
      return offset;
    }

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkEntryNotNull;
import static com.google.common.collect.Maps.immutableEntry;
import static java.util.Objects.requireNonNull;

            

Reported by PMD.

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

Line: 72

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V>
    implements Serializable {

  /**
   * Returns an empty multimap.
   *
   * <p><b>Performance note:</b> the instance returned is a singleton.

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 113

                 * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion
   * order described in the <a href="#iteration">class documentation</a>.
   */
  public static <K, V> ImmutableMultimap<K, V> of(
      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
  }

  // looking for of() with > 5 entries? Use the builder instead.

            

Reported by PMD.

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

Line: 148

                 * @since 2.0
   */
  @DoNotMock
  public static class Builder<K, V> {
    final Map<K, Collection<V>> builderMap;
    @CheckForNull Comparator<? super K> keyComparator;
    @CheckForNull Comparator<? super V> valueComparator;

    /**

            

Reported by PMD.

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

Line: 149

                 */
  @DoNotMock
  public static class Builder<K, V> {
    final Map<K, Collection<V>> builderMap;
    @CheckForNull Comparator<? super K> keyComparator;
    @CheckForNull Comparator<? super V> valueComparator;

    /**
     * Creates a new builder. The returned builder is equivalent to the builder generated by {@link

            

Reported by PMD.

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

Line: 150

                @DoNotMock
  public static class Builder<K, V> {
    final Map<K, Collection<V>> builderMap;
    @CheckForNull Comparator<? super K> keyComparator;
    @CheckForNull Comparator<? super V> valueComparator;

    /**
     * Creates a new builder. The returned builder is equivalent to the builder generated by {@link
     * ImmutableMultimap#builder}.

            

Reported by PMD.

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

Line: 151

                public static class Builder<K, V> {
    final Map<K, Collection<V>> builderMap;
    @CheckForNull Comparator<? super K> keyComparator;
    @CheckForNull Comparator<? super V> valueComparator;

    /**
     * Creates a new builder. The returned builder is equivalent to the builder generated by {@link
     * ImmutableMultimap#builder}.
     */

            

Reported by PMD.

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

Line: 173

                    if (valueCollection == null) {
        builderMap.put(key, valueCollection = newMutableValueCollection());
      }
      valueCollection.add(value);
      return this;
    }

    /**
     * Adds an entry to the built multimap.

            

Reported by PMD.

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSortedMap.java
35 issues
Avoid reassigning parameters such as 'toKey'
Design

Line: 316

                  return newView(sortedDelegate.headMap(toKey));
  }

  ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) {
    checkNotNull(toKey);
    if (inclusive) {
      K tmp = higher(toKey);
      if (tmp == null) {
        return this;

            

Reported by PMD.

Avoid reassigning parameters such as 'fromKey'
Design

Line: 347

                  return newView(sortedDelegate.tailMap(fromKey));
  }

  public ImmutableSortedMap<K, V> tailMap(K fromKey, boolean inclusive) {
    checkNotNull(fromKey);
    if (!inclusive) {
      fromKey = higher(fromKey);
      if (fromKey == null) {
        return new Builder<K, V>(this.comparator).build();

            

Reported by PMD.

Possible God Class (WMC=49, ATFD=7, TCC=24.955%)
Design

Line: 41

               *
 * @author Hayward Chan
 */
public final class ImmutableSortedMap<K, V> extends ForwardingImmutableMap<K, V>
    implements SortedMap<K, V> {

  @SuppressWarnings("unchecked")
  static final Comparator NATURAL_ORDER = Ordering.natural();


            

Reported by PMD.

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

Line: 42

               * @author Hayward Chan
 */
public final class ImmutableSortedMap<K, V> extends ForwardingImmutableMap<K, V>
    implements SortedMap<K, V> {

  @SuppressWarnings("unchecked")
  static final Comparator NATURAL_ORDER = Ordering.natural();

  // This reference is only used by GWT compiler to infer the keys and values

            

Reported by PMD.

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

Line: 44

              public final class ImmutableSortedMap<K, V> extends ForwardingImmutableMap<K, V>
    implements SortedMap<K, V> {

  @SuppressWarnings("unchecked")
  static final Comparator NATURAL_ORDER = Ordering.natural();

  // This reference is only used by GWT compiler to infer the keys and values
  // of the map that needs to be serialized.
  private Comparator<? super K> unusedComparatorForSerialization;

            

Reported by PMD.

Avoid unused private fields such as 'unusedComparatorForSerialization'.
Design

Line: 49

              
  // This reference is only used by GWT compiler to infer the keys and values
  // of the map that needs to be serialized.
  private Comparator<? super K> unusedComparatorForSerialization;
  private K unusedKeyForSerialization;
  private V unusedValueForSerialization;

  private final transient SortedMap<K, V> sortedDelegate;


            

Reported by PMD.

Avoid unused private fields such as 'unusedKeyForSerialization'.
Design

Line: 50

                // This reference is only used by GWT compiler to infer the keys and values
  // of the map that needs to be serialized.
  private Comparator<? super K> unusedComparatorForSerialization;
  private K unusedKeyForSerialization;
  private V unusedValueForSerialization;

  private final transient SortedMap<K, V> sortedDelegate;

  // The comparator used by this map.  It's the same as that of sortedDelegate,

            

Reported by PMD.

Avoid unused private fields such as 'unusedValueForSerialization'.
Design

Line: 51

                // of the map that needs to be serialized.
  private Comparator<? super K> unusedComparatorForSerialization;
  private K unusedKeyForSerialization;
  private V unusedValueForSerialization;

  private final transient SortedMap<K, V> sortedDelegate;

  // The comparator used by this map.  It's the same as that of sortedDelegate,
  // except that when sortedDelegate's comparator is null, it points to a

            

Reported by PMD.

Field comparator has the same name as a method
Error

Line: 61

                // (cpovirk: Is sortedDelegate's comparator really ever null?)
  // The comparator will likely also differ because of our nullAccepting hack.
  // See the bottom of the file for more information about it.
  private final transient Comparator<? super K> comparator;

  ImmutableSortedMap(SortedMap<K, V> delegate, Comparator<? super K> comparator) {
    super(delegate);
    this.comparator = comparator;
    this.sortedDelegate = delegate;

            

Reported by PMD.

Avoid long parameter lists.
Design

Line: 121

                      .build();
  }

  public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V> of(
      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
    return new Builder<K, V>(Ordering.natural())
        .put(k1, v1)
        .put(k2, v2)
        .put(k3, v3)

            

Reported by PMD.

android/guava/src/com/google/common/graph/AbstractValueGraph.java
35 issues
The class 'AbstractValueGraph' has a Standard Cyclomatic Complexity of 4 (Highest = 13).
Design

Line: 42

               */
@Beta
@ElementTypesAreNonnullByDefault
public abstract class AbstractValueGraph<N, V> extends AbstractBaseGraph<N>
    implements ValueGraph<N, V> {

  @Override
  public Graph<N> asGraph() {
    return new AbstractGraph<N>() {

            

Reported by PMD.

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

Line: 42

               */
@Beta
@ElementTypesAreNonnullByDefault
public abstract class AbstractValueGraph<N, V> extends AbstractBaseGraph<N>
    implements ValueGraph<N, V> {

  @Override
  public Graph<N> asGraph() {
    return new AbstractGraph<N>() {

            

Reported by PMD.

The method 'asGraph' has a Modified Cyclomatic Complexity of 13.
Design

Line: 46

                  implements ValueGraph<N, V> {

  @Override
  public Graph<N> asGraph() {
    return new AbstractGraph<N>() {
      @Override
      public Set<N> nodes() {
        return AbstractValueGraph.this.nodes();
      }

            

Reported by PMD.

The method 'asGraph' has a Standard Cyclomatic Complexity of 13.
Design

Line: 46

                  implements ValueGraph<N, V> {

  @Override
  public Graph<N> asGraph() {
    return new AbstractGraph<N>() {
      @Override
      public Set<N> nodes() {
        return AbstractValueGraph.this.nodes();
      }

            

Reported by PMD.

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

Line: 50

                  return new AbstractGraph<N>() {
      @Override
      public Set<N> nodes() {
        return AbstractValueGraph.this.nodes();
      }

      @Override
      public Set<EndpointPair<N>> edges() {
        return AbstractValueGraph.this.edges();

            

Reported by PMD.

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

Line: 50

                  return new AbstractGraph<N>() {
      @Override
      public Set<N> nodes() {
        return AbstractValueGraph.this.nodes();
      }

      @Override
      public Set<EndpointPair<N>> edges() {
        return AbstractValueGraph.this.edges();

            

Reported by PMD.

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

Line: 55

              
      @Override
      public Set<EndpointPair<N>> edges() {
        return AbstractValueGraph.this.edges();
      }

      @Override
      public boolean isDirected() {
        return AbstractValueGraph.this.isDirected();

            

Reported by PMD.

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

Line: 55

              
      @Override
      public Set<EndpointPair<N>> edges() {
        return AbstractValueGraph.this.edges();
      }

      @Override
      public boolean isDirected() {
        return AbstractValueGraph.this.isDirected();

            

Reported by PMD.

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

Line: 60

              
      @Override
      public boolean isDirected() {
        return AbstractValueGraph.this.isDirected();
      }

      @Override
      public boolean allowsSelfLoops() {
        return AbstractValueGraph.this.allowsSelfLoops();

            

Reported by PMD.

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

Line: 60

              
      @Override
      public boolean isDirected() {
        return AbstractValueGraph.this.isDirected();
      }

      @Override
      public boolean allowsSelfLoops() {
        return AbstractValueGraph.this.allowsSelfLoops();

            

Reported by PMD.

guava-tests/test/com/google/common/escape/UnicodeEscaperTest.java
35 issues
Return an empty array rather than null.
Error

Line: 42

                private static final UnicodeEscaper NOP_ESCAPER =
      new UnicodeEscaper() {
        @Override
        protected char[] escape(int c) {
          return null;
        }
      };

  // Escapes everything except [a-zA-Z0-9]

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 171

                        }
          // Inefficient implementation that defines all letters as escapable.
          @Override
          protected int nextEscapeIndex(CharSequence csq, int index, int end) {
            while (index < end && !Character.isLetter(csq.charAt(index))) {
              index++;
            }
            return index;
          }

            

Reported by PMD.

Do not add empty strings
Performance

Line: 31

              public class UnicodeEscaperTest extends TestCase {

  private static final String SMALLEST_SURROGATE =
      "" + Character.MIN_HIGH_SURROGATE + Character.MIN_LOW_SURROGATE;
  private static final String LARGEST_SURROGATE =
      "" + Character.MAX_HIGH_SURROGATE + Character.MAX_LOW_SURROGATE;

  private static final String TEST_STRING =
      "\0abyz\u0080\u0100\u0800\u1000ABYZ\uffff" + SMALLEST_SURROGATE + "0189" + LARGEST_SURROGATE;

            

Reported by PMD.

Do not add empty strings
Performance

Line: 33

                private static final String SMALLEST_SURROGATE =
      "" + Character.MIN_HIGH_SURROGATE + Character.MIN_LOW_SURROGATE;
  private static final String LARGEST_SURROGATE =
      "" + Character.MAX_HIGH_SURROGATE + Character.MAX_LOW_SURROGATE;

  private static final String TEST_STRING =
      "\0abyz\u0080\u0100\u0800\u1000ABYZ\uffff" + SMALLEST_SURROGATE + "0189" + LARGEST_SURROGATE;

  // Escapes nothing

            

Reported by PMD.

No need to call String.valueOf to append to a string.
Performance

Line: 54

                      protected char[] escape(int cp) {
          return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z') || ('0' <= cp && cp <= '9')
              ? null
              : ("[" + String.valueOf(cp) + "]").toCharArray();
        }
      };

  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;

            

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

                      }
      };

  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;
    assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

              
  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;
    assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {
    UnicodeEscaper e = SIMPLE_ESCAPER;
    String 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: 63

                  assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {
    UnicodeEscaper e = SIMPLE_ESCAPER;
    String expected =
        "[0]abyz[128][256][2048][4096]ABYZ[65535]"
            + "["
            + Character.MIN_SUPPLEMENTARY_CODE_POINT

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 73

                          + "0189["
            + Character.MAX_CODE_POINT
            + "]";
    assertEquals(expected, escapeAsString(e, TEST_STRING));
  }

  public void testGrowBuffer() { // need to grow past an initial 1024 byte buffer
    StringBuilder input = new StringBuilder();
    StringBuilder expected = new StringBuilder();

            

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(expected, escapeAsString(e, TEST_STRING));
  }

  public void testGrowBuffer() { // need to grow past an initial 1024 byte buffer
    StringBuilder input = new StringBuilder();
    StringBuilder expected = new StringBuilder();
    for (int i = 256; i < 1024; i++) {
      input.append((char) i);
      expected.append("[" + i + "]");

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapComputeTester.java
35 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: 41

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapComputeTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testCompute_absentToPresent() {
    assertEquals(
        "Map.compute(absent, functionReturningValue) should return value",
        v3(),
        getMap()

            

Reported by PMD.

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

Line: 42

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapComputeTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testCompute_absentToPresent() {
    assertEquals(
        "Map.compute(absent, functionReturningValue) should return value",
        v3(),
        getMap()
            .compute(

            

Reported by PMD.

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

Line: 46

                  assertEquals(
        "Map.compute(absent, functionReturningValue) should return value",
        v3(),
        getMap()
            .compute(
                k3(),
                (k, v) -> {
                  assertEquals(k3(), k);
                  assertNull(v);

            

Reported by PMD.

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

Line: 55

                                return v3();
                }));
    expectAdded(e3());
    assertEquals(getNumElements() + 1, getMap().size());
  }

  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testCompute_absentToAbsent() {
    assertNull(

            

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

                  assertEquals(getNumElements() + 1, getMap().size());
  }

  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testCompute_absentToAbsent() {
    assertNull(
        "Map.compute(absent, functionReturningNull) should return null",
        getMap()
            .compute(

            

Reported by PMD.

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

Line: 59

                }

  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testCompute_absentToAbsent() {
    assertNull(
        "Map.compute(absent, functionReturningNull) should return null",
        getMap()
            .compute(
                k3(),

            

Reported by PMD.

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

Line: 62

                public void testCompute_absentToAbsent() {
    assertNull(
        "Map.compute(absent, functionReturningNull) should return null",
        getMap()
            .compute(
                k3(),
                (k, v) -> {
                  assertEquals(k3(), k);
                  assertNull(v);

            

Reported by PMD.

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

Line: 71

                                return null;
                }));
    expectUnchanged();
    assertEquals(getNumElements(), getMap().size());
  }

  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  @CollectionSize.Require(absent = ZERO)
  public void testCompute_presentToPresent() {

            

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

                  assertEquals(getNumElements(), getMap().size());
  }

  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  @CollectionSize.Require(absent = ZERO)
  public void testCompute_presentToPresent() {
    assertEquals(
        "Map.compute(present, functionReturningValue) should return new value",
        v3(),

            

Reported by PMD.

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

Line: 76

              
  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  @CollectionSize.Require(absent = ZERO)
  public void testCompute_presentToPresent() {
    assertEquals(
        "Map.compute(present, functionReturningValue) should return new value",
        v3(),
        getMap()
            .compute(

            

Reported by PMD.

android/guava-tests/test/com/google/common/escape/UnicodeEscaperTest.java
35 issues
Return an empty array rather than null.
Error

Line: 42

                private static final UnicodeEscaper NOP_ESCAPER =
      new UnicodeEscaper() {
        @Override
        protected char[] escape(int c) {
          return null;
        }
      };

  // Escapes everything except [a-zA-Z0-9]

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 171

                        }
          // Inefficient implementation that defines all letters as escapable.
          @Override
          protected int nextEscapeIndex(CharSequence csq, int index, int end) {
            while (index < end && !Character.isLetter(csq.charAt(index))) {
              index++;
            }
            return index;
          }

            

Reported by PMD.

Do not add empty strings
Performance

Line: 31

              public class UnicodeEscaperTest extends TestCase {

  private static final String SMALLEST_SURROGATE =
      "" + Character.MIN_HIGH_SURROGATE + Character.MIN_LOW_SURROGATE;
  private static final String LARGEST_SURROGATE =
      "" + Character.MAX_HIGH_SURROGATE + Character.MAX_LOW_SURROGATE;

  private static final String TEST_STRING =
      "\0abyz\u0080\u0100\u0800\u1000ABYZ\uffff" + SMALLEST_SURROGATE + "0189" + LARGEST_SURROGATE;

            

Reported by PMD.

Do not add empty strings
Performance

Line: 33

                private static final String SMALLEST_SURROGATE =
      "" + Character.MIN_HIGH_SURROGATE + Character.MIN_LOW_SURROGATE;
  private static final String LARGEST_SURROGATE =
      "" + Character.MAX_HIGH_SURROGATE + Character.MAX_LOW_SURROGATE;

  private static final String TEST_STRING =
      "\0abyz\u0080\u0100\u0800\u1000ABYZ\uffff" + SMALLEST_SURROGATE + "0189" + LARGEST_SURROGATE;

  // Escapes nothing

            

Reported by PMD.

No need to call String.valueOf to append to a string.
Performance

Line: 54

                      protected char[] escape(int cp) {
          return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z') || ('0' <= cp && cp <= '9')
              ? null
              : ("[" + String.valueOf(cp) + "]").toCharArray();
        }
      };

  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;

            

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

                      }
      };

  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;
    assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

              
  public void testNopEscaper() {
    UnicodeEscaper e = NOP_ESCAPER;
    assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {
    UnicodeEscaper e = SIMPLE_ESCAPER;
    String 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: 63

                  assertEquals(TEST_STRING, escapeAsString(e, TEST_STRING));
  }

  public void testSimpleEscaper() {
    UnicodeEscaper e = SIMPLE_ESCAPER;
    String expected =
        "[0]abyz[128][256][2048][4096]ABYZ[65535]"
            + "["
            + Character.MIN_SUPPLEMENTARY_CODE_POINT

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 73

                          + "0189["
            + Character.MAX_CODE_POINT
            + "]";
    assertEquals(expected, escapeAsString(e, TEST_STRING));
  }

  public void testGrowBuffer() { // need to grow past an initial 1024 byte buffer
    StringBuilder input = new StringBuilder();
    StringBuilder expected = new StringBuilder();

            

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(expected, escapeAsString(e, TEST_STRING));
  }

  public void testGrowBuffer() { // need to grow past an initial 1024 byte buffer
    StringBuilder input = new StringBuilder();
    StringBuilder expected = new StringBuilder();
    for (int i = 256; i < 1024; i++) {
      input.append((char) i);
      expected.append("[" + i + "]");

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java
34 issues
This class has too many methods, consider refactoring it.
Design

Line: 42

              @SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_supportedAllPresent() {
    assertTrue(
        "addAll(n, allPresent) should return true",

            

Reported by PMD.

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

Line: 43

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_supportedAllPresent() {
    assertTrue(
        "addAll(n, allPresent) should return true",
        getList().addAll(0, MinimalCollection.of(e0())));

            

Reported by PMD.

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

Line: 48

                public void testAddAllAtIndex_supportedAllPresent() {
    assertTrue(
        "addAll(n, allPresent) should return true",
        getList().addAll(0, MinimalCollection.of(e0())));
    expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)

            

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

                  expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_unsupportedAllPresent() {
    try {
      getList().addAll(0, MinimalCollection.of(e0()));
      fail("addAll(n, allPresent) should throw");

            

Reported by PMD.

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

Line: 56

                @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_unsupportedAllPresent() {
    try {
      getList().addAll(0, MinimalCollection.of(e0()));
      fail("addAll(n, allPresent) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 63

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_supportedSomePresent() {
    assertTrue(
        "addAll(n, allPresent) should return true",
        getList().addAll(0, MinimalCollection.of(e0(), e3())));

            

Reported by PMD.

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

Line: 68

                public void testAddAllAtIndex_supportedSomePresent() {
    assertTrue(
        "addAll(n, allPresent) should return true",
        getList().addAll(0, MinimalCollection.of(e0(), e3())));
    expectAdded(0, e0(), e3());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 72

                  expectAdded(0, e0(), e3());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_unsupportedSomePresent() {
    try {
      getList().addAll(0, MinimalCollection.of(e0(), e3()));
      fail("addAll(n, allPresent) should throw");

            

Reported by PMD.

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

Line: 76

                @CollectionSize.Require(absent = ZERO)
  public void testAddAllAtIndex_unsupportedSomePresent() {
    try {
      getList().addAll(0, MinimalCollection.of(e0(), e3()));
      fail("addAll(n, allPresent) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
    expectMissing(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: 84

                  expectMissing(e3());
  }

  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAllAtIndex_supportedNothing() {
    assertFalse("addAll(n, nothing) should return false", getList().addAll(0, emptyCollection()));
    expectUnchanged();
  }


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java
34 issues
This class has too many methods, consider refactoring it.
Design

Line: 41

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public abstract class AbstractMapTester<K, V>
    extends AbstractContainerTester<Map<K, V>, Entry<K, V>> {
  protected Map<K, V> getMap() {
    return container;
  }

  @Override

            

Reported by PMD.

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

Line: 48

              
  @Override
  protected Collection<Entry<K, V>> actualContents() {
    return getMap().entrySet();
  }

  /** @see AbstractContainerTester#resetContainer() */
  protected final void resetMap() {
    resetContainer();

            

Reported by PMD.

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

Line: 62

              
  protected void expectMissingKeys(K... elements) {
    for (K element : elements) {
      assertFalse("Should not contain key " + element, getMap().containsKey(element));
    }
  }

  protected void expectMissingValues(V... elements) {
    for (V element : elements) {

            

Reported by PMD.

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

Line: 68

              
  protected void expectMissingValues(V... elements) {
    for (V element : elements) {
      assertFalse("Should not contain value " + element, getMap().containsValue(element));
    }
  }

  /** @return an array of the proper size with {@code null} as the key of the middle element. */
  protected Entry<K, V>[] createArrayWithNullKey() {

            

Reported by PMD.

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

Line: 77

                  Entry<K, V>[] array = createSamplesArray();
    final int nullKeyLocation = getNullLocation();
    final Entry<K, V> oldEntry = array[nullKeyLocation];
    array[nullKeyLocation] = entry(null, oldEntry.getValue());
    return array;
  }

  protected V getValueForNullKey() {
    return getEntryNullReplaces().getValue();

            

Reported by PMD.

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

Line: 82

                }

  protected V getValueForNullKey() {
    return getEntryNullReplaces().getValue();
  }

  protected K getKeyForNullValue() {
    return getEntryNullReplaces().getKey();
  }

            

Reported by PMD.

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

Line: 86

                }

  protected K getKeyForNullValue() {
    return getEntryNullReplaces().getKey();
  }

  private Entry<K, V> getEntryNullReplaces() {
    Iterator<Entry<K, V>> entries = getSampleElements().iterator();
    for (int i = 0; i < getNullLocation(); i++) {

            

Reported by PMD.

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

Line: 90

                }

  private Entry<K, V> getEntryNullReplaces() {
    Iterator<Entry<K, V>> entries = getSampleElements().iterator();
    for (int i = 0; i < getNullLocation(); i++) {
      entries.next();
    }
    return entries.next();
  }

            

Reported by PMD.

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

Line: 102

                  Entry<K, V>[] array = createSamplesArray();
    final int nullValueLocation = getNullLocation();
    final Entry<K, V> oldEntry = array[nullValueLocation];
    array[nullValueLocation] = entry(oldEntry.getKey(), null);
    return array;
  }

  protected void initMapWithNullKey() {
    resetMap(createArrayWithNullKey());

            

Reported by PMD.

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

Line: 122

                 */
  protected void expectNullKeyMissingWhenNullKeysUnsupported(String message) {
    try {
      assertFalse(message, getMap().containsKey(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java
34 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: 32

               */
public class AbstractByteHasherTest extends TestCase {

  public void testBytes() {
    TestHasher hasher = new TestHasher(); // byte order insignificant here
    byte[] expected = {1, 2, 3, 4, 5, 6, 7, 8};
    hasher.putByte((byte) 1);
    hasher.putBytes(new byte[] {2, 3, 4, 5, 6});
    hasher.putByte((byte) 7);

            

Reported by PMD.

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

Line: 32

               */
public class AbstractByteHasherTest extends TestCase {

  public void testBytes() {
    TestHasher hasher = new TestHasher(); // byte order insignificant here
    byte[] expected = {1, 2, 3, 4, 5, 6, 7, 8};
    hasher.putByte((byte) 1);
    hasher.putBytes(new byte[] {2, 3, 4, 5, 6});
    hasher.putByte((byte) 7);

            

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

                  hasher.assertBytes(expected);
  }

  public void testShort() {
    TestHasher hasher = new TestHasher();
    hasher.putShort((short) 0x0201);
    hasher.assertBytes(new byte[] {1, 2});
  }


            

Reported by PMD.

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

Line: 43

                  hasher.assertBytes(expected);
  }

  public void testShort() {
    TestHasher hasher = new TestHasher();
    hasher.putShort((short) 0x0201);
    hasher.assertBytes(new byte[] {1, 2});
  }


            

Reported by PMD.

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

Line: 49

                  hasher.assertBytes(new byte[] {1, 2});
  }

  public void testInt() {
    TestHasher hasher = new TestHasher();
    hasher.putInt(0x04030201);
    hasher.assertBytes(new byte[] {1, 2, 3, 4});
  }


            

Reported by PMD.

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

Line: 49

                  hasher.assertBytes(new byte[] {1, 2});
  }

  public void testInt() {
    TestHasher hasher = new TestHasher();
    hasher.putInt(0x04030201);
    hasher.assertBytes(new byte[] {1, 2, 3, 4});
  }


            

Reported by PMD.

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

Line: 55

                  hasher.assertBytes(new byte[] {1, 2, 3, 4});
  }

  public void testLong() {
    TestHasher hasher = new TestHasher();
    hasher.putLong(0x0807060504030201L);
    hasher.assertBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8});
  }


            

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

                  hasher.assertBytes(new byte[] {1, 2, 3, 4});
  }

  public void testLong() {
    TestHasher hasher = new TestHasher();
    hasher.putLong(0x0807060504030201L);
    hasher.assertBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8});
  }


            

Reported by PMD.

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

Line: 61

                  hasher.assertBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8});
  }

  public void testChar() {
    TestHasher hasher = new TestHasher();
    hasher.putChar((char) 0x0201);
    hasher.assertBytes(new byte[] {1, 2});
  }


            

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

                  hasher.assertBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8});
  }

  public void testChar() {
    TestHasher hasher = new TestHasher();
    hasher.putChar((char) 0x0201);
    hasher.assertBytes(new byte[] {1, 2});
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/FauxveridesTest.java
34 issues
Avoid reassigning parameters such as 'descendant'
Design

Line: 150

                }

  /** [descendant, ancestor) */
  private static Set<Class<?>> getClassesBetween(Class<?> descendant, Class<?> ancestor) {
    Set<Class<?>> classes = newHashSet();

    while (!descendant.equals(ancestor)) {
      classes.add(descendant);
      descendant = descendant.getSuperclass();

            

Reported by PMD.

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

Line: 45

               *
 * @author Chris Povirk
 */
public class FauxveridesTest extends TestCase {
  public void testImmutableBiMap() {
    doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
  }

  public void testImmutableListMultimap() {

            

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

               * @author Chris Povirk
 */
public class FauxveridesTest extends TestCase {
  public void testImmutableBiMap() {
    doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
  }

  public void testImmutableListMultimap() {
    doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);

            

Reported by PMD.

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

Line: 46

               * @author Chris Povirk
 */
public class FauxveridesTest extends TestCase {
  public void testImmutableBiMap() {
    doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
  }

  public void testImmutableListMultimap() {
    doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);

            

Reported by PMD.

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

Line: 50

                  doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
  }

  public void testImmutableListMultimap() {
    doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSetMultimap() {
    doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);

            

Reported by PMD.

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

Line: 50

                  doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
  }

  public void testImmutableListMultimap() {
    doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSetMultimap() {
    doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);

            

Reported by PMD.

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

Line: 54

                  doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSetMultimap() {
    doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSortedMap() {
    doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);

            

Reported by PMD.

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

Line: 54

                  doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSetMultimap() {
    doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSortedMap() {
    doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);

            

Reported by PMD.

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

Line: 58

                  doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSortedMap() {
    doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
  }

  public void testImmutableSortedSet() {
    doHasAllFauxveridesTest(ImmutableSortedSet.class, ImmutableSet.class);

            

Reported by PMD.

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

Line: 58

                  doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
  }

  public void testImmutableSortedMap() {
    doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
  }

  public void testImmutableSortedSet() {
    doHasAllFauxveridesTest(ImmutableSortedSet.class, ImmutableSet.class);

            

Reported by PMD.