The following issues were found

android/guava-tests/test/com/google/common/collect/NewCustomTableTest.java
10 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: 49

                  return table;
  }

  public void testRowKeySetOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
  }

  public void testRowOrdering() {

            

Reported by PMD.

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

Line: 50

                }

  public void testRowKeySetOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
  }

  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');

            

Reported by PMD.

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

Line: 51

              
  public void testRowKeySetOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
  }

  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();

            

Reported by PMD.

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

Line: 51

              
  public void testRowKeySetOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
  }

  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();

            

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

                  assertThat(table.rowKeySet()).containsExactly("foo", "bar").inOrder();
  }

  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
  }
}

            

Reported by PMD.

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

Line: 56

              
  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
  }
}

            

Reported by PMD.

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

Line: 56

              
  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
  }
}

            

Reported by PMD.

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

Line: 56

              
  public void testRowOrdering() {
    table = create("foo", 3, 'a', "bar", 1, 'b', "foo", 2, 'c');
    assertThat(table.row("foo").keySet()).containsExactly(2, 3).inOrder();
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'factory' (lines '36'-'47').
Error

Line: 36

              
  @Override
  protected Table<String, Integer, Character> create(Object... data) {
    Supplier<TreeMap<Integer, Character>> factory =
        new Supplier<TreeMap<Integer, Character>>() {
          @Override
          public TreeMap<Integer, Character> get() {
            return Maps.newTreeMap();
          }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'factory' (lines '36'-'47').
Error

Line: 36

              
  @Override
  protected Table<String, Integer, Character> create(Object... data) {
    Supplier<TreeMap<Integer, Character>> factory =
        new Supplier<TreeMap<Integer, Character>>() {
          @Override
          public TreeMap<Integer, Character> get() {
            return Maps.newTreeMap();
          }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java
10 issues
Avoid throwing null pointer exceptions.
Design

Line: 58

                  if (!allowNulls) {
      for (Object element : contents) {
        if (element == null) {
          throw new NullPointerException();
        }
      }
    }
  }


            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 74

                  if (!allowNulls) {
      // behave badly
      if (object == null) {
        throw new NullPointerException();
      }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);
  }

            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 87

                    for (Object object : collection) {
        // behave badly
        if (object == null) {
          throw new NullPointerException();
        }
      }
    }
    return super.containsAll(collection);
  }

            

Reported by PMD.

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

Line: 32

               * @author Kevin Bourrillion
 */
@GwtCompatible
public class MinimalCollection<E> extends AbstractCollection<E> {
  // TODO: expose allow nulls parameter?

  public static <E> MinimalCollection<E> of(E... contents) {
    return new MinimalCollection<E>(Object.class, true, contents);
  }

            

Reported by PMD.

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

Line: 44

                  return new MinimalCollection<E>(type, true, contents);
  }

  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {

            

Reported by PMD.

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

Line: 45

                }

  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {
    // TODO: consider making it shuffle the contents to test iteration order.

            

Reported by PMD.

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

Line: 46

              
  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {
    // TODO: consider making it shuffle the contents to test iteration order.
    this.contents = Platform.clone(contents);

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 73

                public boolean contains(Object object) {
    if (!allowNulls) {
      // behave badly
      if (object == null) {
        throw new NullPointerException();
      }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);

            

Reported by PMD.

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

Line: 78

                    }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);
  }

  @Override
  public boolean containsAll(Collection<?> collection) {
    if (!allowNulls) {

            

Reported by PMD.

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

Line: 96

              
  @Override
  public Iterator<E> iterator() {
    return Arrays.asList(contents).iterator();
  }

  @Override
  public Object[] toArray() {
    Object[] result = new Object[contents.length];

            

Reported by PMD.

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

Line: 32

              public class ToStringHelperBenchmark {

  @Param({"0", "1", "5"})
  int dataSize;

  @Param({"false", "true"})
  boolean omitNulls;

  enum Dataset {

            

Reported by PMD.

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

Line: 35

                int dataSize;

  @Param({"false", "true"})
  boolean omitNulls;

  enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 40

                enum Dataset {
    SMALL {
      void addEntries(MoreObjects.ToStringHelper helper) {
        helper
            .add(SHORT_NAME, 10)
            .addValue(10L)
            .add(SHORT_NAME, 3.14f)
            .addValue(3.14d)
            .add(LONG_NAME, false)

            

Reported by PMD.

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

Line: 114

                  void addEntries(MoreObjects.ToStringHelper helper) {}
  }

  @Param Dataset dataset;

  private static final String SHORT_NAME = "userId";
  private static final String LONG_NAME = "fluxCapacitorFailureRate95Percentile";

  private MoreObjects.ToStringHelper newHelper() {

            

Reported by PMD.

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

Line: 135

                    for (int j = 0; j < dataSize; ++j) {
        dataset.addEntries(helper);
      }
      dummy ^= helper.toString().hashCode();
    }
    return dummy;
  }

  // When omitEmptyValues() is released, remove this method and add a new @Param "omitEmptyValues".

            

Reported by PMD.

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

Line: 135

                    for (int j = 0; j < dataSize; ++j) {
        dataset.addEntries(helper);
      }
      dummy ^= helper.toString().hashCode();
    }
    return dummy;
  }

  // When omitEmptyValues() is released, remove this method and add a new @Param "omitEmptyValues".

            

Reported by PMD.

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

Line: 44

               * @author Jared Levy
 */
@GwtIncompatible
public class TestsForQueuesInJavaUtil {
  public static Test suite() {
    return new TestsForQueuesInJavaUtil().allTests();
  }

  public Test allTests() {

            

Reported by PMD.

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

Line: 45

               */
@GwtIncompatible
public class TestsForQueuesInJavaUtil {
  public static Test suite() {
    return new TestsForQueuesInJavaUtil().allTests();
  }

  public Test allTests() {
    TestSuite suite = new TestSuite();

            

Reported by PMD.

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

Line: 94

                  return Collections.emptySet();
  }

  public Test testsForArrayDeque() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new ArrayDeque<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForLinkedList() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new LinkedList<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForArrayBlockingQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new ArrayBlockingQueue<>(100, false, MinimalCollection.of(elements));

            

Reported by PMD.

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

Line: 143

                      .createTestSuite();
  }

  public Test testsForConcurrentLinkedQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new ConcurrentLinkedQueue<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForLinkedBlockingDeque() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new LinkedBlockingDeque<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForLinkedBlockingQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new LinkedBlockingQueue<>(MinimalCollection.of(elements));

            

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

                // also mean that the iterator returns the head element first, which those
  // don't.

  public Test testsForPriorityBlockingQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new PriorityBlockingQueue<>(MinimalCollection.of(elements));

            

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

                      .createTestSuite();
  }

  public Test testsForPriorityQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new PriorityQueue<>(MinimalCollection.of(elements));

            

Reported by PMD.

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

Line: 31

              public class ImmutableListCreationBenchmark {

  @Param({"10", "1000", "1000000"})
  int size;

  private static final Object OBJECT = new Object();

  @Benchmark
  int builderAdd(int reps) {

            

Reported by PMD.

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

Line: 44

                    for (int i = 0; i < size; i++) {
        builder.add(OBJECT);
      }
      dummy += builder.build().size();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 54

                  int size = this.size;
    int dummy = 0;
    for (int rep = 0; rep < reps; rep++) {
      ImmutableList.Builder<Object> builder = new ImmutableList.Builder<>(size);
      for (int i = 0; i < size; i++) {
        builder.add(OBJECT);
      }
      dummy += builder.build().size();
    }

            

Reported by PMD.

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

Line: 58

                    for (int i = 0; i < size; i++) {
        builder.add(OBJECT);
      }
      dummy += builder.build().size();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 72

                    for (int i = 0; i < size; i++) {
        builder.add(OBJECT);
      }
      dummy += ImmutableList.copyOf(builder).size();
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 86

                    for (int i = 0; i < size; i++) {
        builder.add(OBJECT);
      }
      tmp += ImmutableList.copyOf(builder).size();
    }
    return tmp;
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'size' (lines '37'-'47').
Error

Line: 37

              
  @Benchmark
  int builderAdd(int reps) {
    int size = this.size;
    int dummy = 0;
    for (int rep = 0; rep < reps; rep++) {
      ImmutableList.Builder<Object> builder = ImmutableList.builder();
      for (int i = 0; i < size; i++) {
        builder.add(OBJECT);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'size' (lines '51'-'61').
Error

Line: 51

              
  @Benchmark
  int preSizedBuilderAdd(int reps) {
    int size = this.size;
    int dummy = 0;
    for (int rep = 0; rep < reps; rep++) {
      ImmutableList.Builder<Object> builder = new ImmutableList.Builder<>(size);
      for (int i = 0; i < size; i++) {
        builder.add(OBJECT);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'size' (lines '65'-'75').
Error

Line: 65

              
  @Benchmark
  int copyArrayList(int reps) {
    int size = this.size;
    int dummy = 0;
    for (int rep = 0; rep < reps; rep++) {
      List<Object> builder = Lists.newArrayList();
      for (int i = 0; i < size; i++) {
        builder.add(OBJECT);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'size' (lines '79'-'89').
Error

Line: 79

              
  @Benchmark
  int copyPreSizedArrayList(int reps) {
    int size = this.size;
    int tmp = 0;
    for (int rep = 0; rep < reps; rep++) {
      List<Object> builder = Lists.newArrayListWithCapacity(size);
      for (int i = 0; i < size; i++) {
        builder.add(OBJECT);

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapToStringTester.java
10 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: 38

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapToStringTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  @CollectionSize.Require(ZERO)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringEmpty() {
    assertEquals("{}", multimap().toString());
  }


            

Reported by PMD.

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

Line: 41

                @CollectionSize.Require(ZERO)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringEmpty() {
    assertEquals("{}", multimap().toString());
  }

  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringSingleton() {

            

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

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

  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringSingleton() {
    assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString());
  }


            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(ONE)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringSingleton() {
    assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  @MapFeature.Require(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: 50

                  assertEquals("{" + k0() + "=[" + v0() + "]}", multimap().toString());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testToStringWithNullKey() {
    initMultimapWithNullKey();
    testToStringMatchesAsMap();

            

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

                  testToStringMatchesAsMap();
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testToStringWithNullValue() {
    initMultimapWithNullValue();
    testToStringMatchesAsMap();

            

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

                  testToStringMatchesAsMap();
  }

  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringMatchesAsMap() {
    assertEquals(multimap().asMap().toString(), multimap().toString());
  }
}

            

Reported by PMD.

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

Line: 68

              
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringMatchesAsMap() {
    assertEquals(multimap().asMap().toString(), multimap().toString());
  }
}

            

Reported by PMD.

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

Line: 68

              
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringMatchesAsMap() {
    assertEquals(multimap().asMap().toString(), multimap().toString());
  }
}

            

Reported by PMD.

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

Line: 68

              
  @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
  public void testToStringMatchesAsMap() {
    assertEquals(multimap().asMap().toString(), multimap().toString());
  }
}

            

Reported by PMD.

android/guava/src/com/google/common/escape/ArrayBasedUnicodeEscaper.java
10 issues
Avoid reassigning parameters such as 'safeMin'
Design

Line: 99

                 */
  protected ArrayBasedUnicodeEscaper(
      ArrayBasedEscaperMap escaperMap,
      int safeMin,
      int safeMax,
      @Nullable String unsafeReplacement) {
    checkNotNull(escaperMap); // GWT specific check (do not optimize)
    this.replacements = escaperMap.getReplacementArray();
    this.replacementsLength = replacements.length;

            

Reported by PMD.

Avoid reassigning parameters such as 'safeMax'
Design

Line: 100

                protected ArrayBasedUnicodeEscaper(
      ArrayBasedEscaperMap escaperMap,
      int safeMin,
      int safeMax,
      @Nullable String unsafeReplacement) {
    checkNotNull(escaperMap); // GWT specific check (do not optimize)
    this.replacements = escaperMap.getReplacementArray();
    this.replacementsLength = replacements.length;
    if (safeMax < safeMin) {

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 182

              
  /* Overridden for performance. */
  @Override
  protected final int nextEscapeIndex(CharSequence csq, int index, int end) {
    while (index < end) {
      char c = csq.charAt(index);
      if ((c < replacementsLength && replacements[c] != null)
          || c > safeMaxChar
          || c < safeMinChar) {

            

Reported by PMD.

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

Line: 49

              @ElementTypesAreNonnullByDefault
public abstract class ArrayBasedUnicodeEscaper extends UnicodeEscaper {
  // The replacement array (see ArrayBasedEscaperMap).
  private final char[][] replacements;
  // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first code point in the safe range.
  private final int safeMin;
  // The last code point in the safe range.

            

Reported by PMD.

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

Line: 51

                // The replacement array (see ArrayBasedEscaperMap).
  private final char[][] replacements;
  // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first code point in the safe range.
  private final int safeMin;
  // The last code point in the safe range.
  private final int safeMax;


            

Reported by PMD.

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

Line: 53

                // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first code point in the safe range.
  private final int safeMin;
  // The last code point in the safe range.
  private final int safeMax;

  // Cropped values used in the fast path range checks.
  private final char safeMinChar;

            

Reported by PMD.

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

Line: 55

                // The first code point in the safe range.
  private final int safeMin;
  // The last code point in the safe range.
  private final int safeMax;

  // Cropped values used in the fast path range checks.
  private final char safeMinChar;
  private final char safeMaxChar;


            

Reported by PMD.

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

Line: 58

                private final int safeMax;

  // Cropped values used in the fast path range checks.
  private final char safeMinChar;
  private final char safeMaxChar;

  /**
   * Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
   * safe range. If {@code safeMax < safeMin} then no code points are considered safe.

            

Reported by PMD.

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

Line: 59

              
  // Cropped values used in the fast path range checks.
  private final char safeMinChar;
  private final char safeMaxChar;

  /**
   * Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
   * safe range. If {@code safeMax < safeMin} then no code points are considered safe.
   *

            

Reported by PMD.

Avoid unused constructor parameters such as 'unsafeReplacement'.
Design

Line: 101

                    ArrayBasedEscaperMap escaperMap,
      int safeMin,
      int safeMax,
      @Nullable String unsafeReplacement) {
    checkNotNull(escaperMap); // GWT specific check (do not optimize)
    this.replacements = escaperMap.getReplacementArray();
    this.replacementsLength = replacements.length;
    if (safeMax < safeMin) {
      // If the safe range is empty, set the range limits to opposite extremes

            

Reported by PMD.

android/guava/src/com/google/common/base/CaseFormat.java
10 issues
Avoid assignments in operands
Error

Line: 137

                  StringBuilder out = null;
    int i = 0;
    int j = -1;
    while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators
        out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 140

                  while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators
        out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {
        requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
      }
      out.append(format.wordSeparator);

            

Reported by PMD.

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

Line: 140

                  while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators
        out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {
        requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
      }
      out.append(format.wordSeparator);

            

Reported by PMD.

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

Line: 143

                      out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {
        requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
      }
      out.append(format.wordSeparator);
      i = j + wordSeparator.length();
    }
    return (i == 0)

            

Reported by PMD.

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

Line: 150

                  }
    return (i == 0)
        ? format.normalizeFirstWord(s)
        : requireNonNull(out).append(format.normalizeWord(s.substring(i))).toString();
  }

  /**
   * Returns a {@code Converter} that converts strings from this format to {@code targetFormat}.
   *

            

Reported by PMD.

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

Line: 150

                  }
    return (i == 0)
        ? format.normalizeFirstWord(s)
        : requireNonNull(out).append(format.normalizeWord(s.substring(i))).toString();
  }

  /**
   * Returns a {@code Converter} that converts strings from this format to {@code targetFormat}.
   *

            

Reported by PMD.

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

Line: 165

                private static final class StringConverter extends Converter<String, String>
      implements Serializable {

    private final CaseFormat sourceFormat;
    private final CaseFormat targetFormat;

    StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat) {
      this.sourceFormat = checkNotNull(sourceFormat);
      this.targetFormat = checkNotNull(targetFormat);

            

Reported by PMD.

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

Line: 166

                    implements Serializable {

    private final CaseFormat sourceFormat;
    private final CaseFormat targetFormat;

    StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat) {
      this.sourceFormat = checkNotNull(sourceFormat);
      this.targetFormat = checkNotNull(targetFormat);
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'out' (lines '134'-'140').
Error

Line: 134

                /** Enum values can override for performance reasons. */
  String convert(CaseFormat format, String s) {
    // deal with camel conversion
    StringBuilder out = null;
    int i = 0;
    int j = -1;
    while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators

            

Reported by PMD.

Found 'DU'-anomaly for variable 'j' (lines '137'-'151').
Error

Line: 137

                  StringBuilder out = null;
    int i = 0;
    int j = -1;
    while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators
        out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {

            

Reported by PMD.

android/guava/src/com/google/common/primitives/UnsignedBytes.java
10 issues
Avoid throwing raw exception types.
Design

Line: 329

                          && (BYTE_ARRAY_BASE_OFFSET % 8) == 0
            // sanity check - this should never fail
            && theUnsafe.arrayIndexScale(byte[].class) == 1)) {
          throw new Error(); // force fallback to PureJavaComparator
        }
      }

      /**
       * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 362

                              }
              });
        } catch (java.security.PrivilegedActionException e) {
          throw new RuntimeException("Could not initialize intrinsics", e.getCause());
        }
      }

      @Override
      public int compare(byte[] left, byte[] right) {

            

Reported by PMD.

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

Line: 48

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class UnsignedBytes {
  private UnsignedBytes() {}

  /**
   * The largest power of two that can be represented as an unsigned {@code byte}.
   *

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 289

                 * available.
   */
  @VisibleForTesting
  static class LexicographicalComparatorHolder {
    static final String UNSAFE_COMPARATOR_NAME =
        LexicographicalComparatorHolder.class.getName() + "$UnsafeComparator";

    static final Comparator<byte[]> BEST_COMPARATOR = getBestComparator();


            

Reported by PMD.

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

Line: 341

                     */
      private static sun.misc.Unsafe getUnsafe() {
        try {
          return sun.misc.Unsafe.getUnsafe();
        } catch (SecurityException e) {
          // that's okay; try reflection instead
        }
        try {
          return java.security.AccessController.doPrivileged(

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 342

                    private static sun.misc.Unsafe getUnsafe() {
        try {
          return sun.misc.Unsafe.getUnsafe();
        } catch (SecurityException e) {
          // that's okay; try reflection instead
        }
        try {
          return java.security.AccessController.doPrivileged(
              new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {

            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 362

                              }
              });
        } catch (java.security.PrivilegedActionException e) {
          throw new RuntimeException("Could not initialize intrinsics", e.getCause());
        }
      }

      @Override
      public int compare(byte[] left, byte[] right) {

            

Reported by PMD.

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

Line: 443

                      Class<?> theClass = Class.forName(UNSAFE_COMPARATOR_NAME);

        // requireNonNull is safe because the class is an enum.
        Object[] constants = requireNonNull(theClass.getEnumConstants());

        // yes, UnsafeComparator does implement Comparator<byte[]>
        @SuppressWarnings("unchecked")
        Comparator<byte[]> comparator = (Comparator<byte[]>) constants[0];
        return comparator;

            

Reported by PMD.

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

Line: 449

                      @SuppressWarnings("unchecked")
        Comparator<byte[]> comparator = (Comparator<byte[]>) constants[0];
        return comparator;
      } catch (Throwable t) { // ensure we really catch *everything*
        return lexicographicalComparatorJavaImpl();
      }
    }
  }


            

Reported by PMD.

Avoid importing anything from the sun.* packages
Error

Line: 29

              import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Comparator;
import sun.misc.Unsafe;

/**
 * Static utility methods pertaining to {@code byte} primitives that interpret values as
 * <i>unsigned</i> (that is, any negative value {@code b} is treated as the positive value {@code
 * 256 + b}). The corresponding methods that treat the values as signed are found in {@link

            

Reported by PMD.

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

Line: 142

               *
 * [*] In annotating this class, we're ignoring LegacyConverter.
 */
public abstract class Converter<A, B> implements Function<A, B> {
  private final boolean handleNullAutomatically;

  // We lazily cache the reverse view to avoid allocating on every call to reverse().
  @LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;


            

Reported by PMD.

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

Line: 143

               * [*] In annotating this class, we're ignoring LegacyConverter.
 */
public abstract class Converter<A, B> implements Function<A, B> {
  private final boolean handleNullAutomatically;

  // We lazily cache the reverse view to avoid allocating on every call to reverse().
  @LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;

  /** Constructor for use by subclasses. */

            

Reported by PMD.

Field reverse has the same name as a method
Error

Line: 146

                private final boolean handleNullAutomatically;

  // We lazily cache the reverse view to avoid allocating on every call to reverse().
  @LazyInit @RetainedWith @CheckForNull private transient Converter<B, A> reverse;

  /** Constructor for use by subclasses. */
  protected Converter() {
    this(true);
  }

            

Reported by PMD.

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

Line: 318

              
  private static final class ReverseConverter<A, B> extends Converter<B, A>
      implements Serializable {
    final Converter<A, B> original;

    ReverseConverter(Converter<A, B> original) {
      this.original = original;
    }


            

Reported by PMD.

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

Line: 398

              
  private static final class ConverterComposition<A, B, C> extends Converter<A, C>
      implements Serializable {
    final Converter<A, B> first;
    final Converter<B, C> second;

    ConverterComposition(Converter<A, B> first, Converter<B, C> second) {
      this.first = first;
      this.second = second;

            

Reported by PMD.

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

Line: 399

                private static final class ConverterComposition<A, B, C> extends Converter<A, C>
      implements Serializable {
    final Converter<A, B> first;
    final Converter<B, C> second;

    ConverterComposition(Converter<A, B> first, Converter<B, C> second) {
      this.first = first;
      this.second = second;
    }

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 511

                 * interchangeable.
   */
  @Override
  public boolean equals(@CheckForNull Object object) {
    return super.equals(object);
  }

  // Static converters


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 537

                  return new FunctionBasedConverter<>(forwardFunction, backwardFunction);
  }

  private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
      implements Serializable {
    private final Function<? super A, ? extends B> forwardFunction;
    private final Function<? super B, ? extends A> backwardFunction;

    private FunctionBasedConverter(

            

Reported by PMD.

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

Line: 539

              
  private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
      implements Serializable {
    private final Function<? super A, ? extends B> forwardFunction;
    private final Function<? super B, ? extends A> backwardFunction;

    private FunctionBasedConverter(
        Function<? super A, ? extends B> forwardFunction,
        Function<? super B, ? extends A> backwardFunction) {

            

Reported by PMD.

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

Line: 540

                private static final class FunctionBasedConverter<A, B> extends Converter<A, B>
      implements Serializable {
    private final Function<? super A, ? extends B> forwardFunction;
    private final Function<? super B, ? extends A> backwardFunction;

    private FunctionBasedConverter(
        Function<? super A, ? extends B> forwardFunction,
        Function<? super B, ? extends A> backwardFunction) {
      this.forwardFunction = checkNotNull(forwardFunction);

            

Reported by PMD.