The following issues were found

guava-tests/test/com/google/common/graph/GraphEquivalenceTest.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                private static final Integer N2 = 2;
  private static final Integer N3 = 3;

  private final EdgeType edgeType;
  private final MutableGraph<Integer> graph;

  // add parameters: directed/undirected
  @Parameters
  public static Collection<Object[]> parameters() {

            

Reported by PMD.

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

Line: 40

                private static final Integer N3 = 3;

  private final EdgeType edgeType;
  private final MutableGraph<Integer> graph;

  // add parameters: directed/undirected
  @Parameters
  public static Collection<Object[]> parameters() {
    return Arrays.asList(new Object[][] {{EdgeType.UNDIRECTED}, {EdgeType.DIRECTED}});

            

Reported by PMD.

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

Line: 56

                private static MutableGraph<Integer> createGraph(EdgeType edgeType) {
    switch (edgeType) {
      case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }

            

Reported by PMD.

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

Line: 56

                private static MutableGraph<Integer> createGraph(EdgeType edgeType) {
    switch (edgeType) {
      case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }

            

Reported by PMD.

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

Line: 58

                    case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }
  }


            

Reported by PMD.

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

Line: 58

                    case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }
  }


            

Reported by PMD.

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

Line: 80

                  graph.addNode(N1);

    MutableGraph<Integer> g2 = createGraph(edgeType);
    g2.addNode(N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets are the same, but node/edge connections differ due to edge type.

            

Reported by PMD.

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

Line: 82

                  MutableGraph<Integer> g2 = createGraph(edgeType);
    g2.addNode(N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets are the same, but node/edge connections differ due to edge type.
  @Test
  public void equivalent_directedVsUndirected() {

            

Reported by PMD.

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

Line: 91

                  graph.putEdge(N1, N2);

    MutableGraph<Integer> g2 = createGraph(oppositeType(edgeType));
    g2.putEdge(N1, N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets and node/edge connections are the same, but directedness differs.

            

Reported by PMD.

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

Line: 93

                  MutableGraph<Integer> g2 = createGraph(oppositeType(edgeType));
    g2.putEdge(N1, N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets and node/edge connections are the same, but directedness differs.
  @Test
  public void equivalent_selfLoop_directedVsUndirected() {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapGetOrDefaultTester.java
24 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 MapGetOrDefaultTester<K, V> extends AbstractMapTester<K, V> {
  @CollectionSize.Require(absent = ZERO)
  public void testGetOrDefault_present() {
    assertEquals(
        "getOrDefault(present, def) should return the associated value",
        v0(),
        getMap().getOrDefault(k0(), v3()));

            

Reported by PMD.

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

Line: 46

                  assertEquals(
        "getOrDefault(present, def) should return the associated value",
        v0(),
        getMap().getOrDefault(k0(), v3()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testGetOrDefault_presentNullDefault() {
    assertEquals(

            

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

                      getMap().getOrDefault(k0(), v3()));
  }

  @CollectionSize.Require(absent = ZERO)
  public void testGetOrDefault_presentNullDefault() {
    assertEquals(
        "getOrDefault(present, null) should return the associated value",
        v0(),
        getMap().getOrDefault(k0(), null));

            

Reported by PMD.

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

Line: 54

                  assertEquals(
        "getOrDefault(present, null) should return the associated value",
        v0(),
        getMap().getOrDefault(k0(), null));
  }

  public void testGetOrDefault_absent() {
    assertEquals(
        "getOrDefault(absent, def) should return the default value",

            

Reported by PMD.

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

Line: 57

                      getMap().getOrDefault(k0(), null));
  }

  public void testGetOrDefault_absent() {
    assertEquals(
        "getOrDefault(absent, def) should return the default value",
        v3(),
        getMap().getOrDefault(k3(), v3()));
  }

            

Reported by PMD.

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

Line: 61

                  assertEquals(
        "getOrDefault(absent, def) should return the default value",
        v3(),
        getMap().getOrDefault(k3(), v3()));
  }

  public void testGetOrDefault_absentNullDefault() {
    assertNull("getOrDefault(absent, null) should return null", getMap().getOrDefault(k3(), null));
  }

            

Reported by PMD.

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

Line: 64

                      getMap().getOrDefault(k3(), v3()));
  }

  public void testGetOrDefault_absentNullDefault() {
    assertNull("getOrDefault(absent, null) should return null", getMap().getOrDefault(k3(), null));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGetOrDefault_absentNull() {

            

Reported by PMD.

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

Line: 65

                }

  public void testGetOrDefault_absentNullDefault() {
    assertNull("getOrDefault(absent, null) should return null", getMap().getOrDefault(k3(), null));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGetOrDefault_absentNull() {
    assertEquals(

            

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

                  assertNull("getOrDefault(absent, null) should return null", getMap().getOrDefault(k3(), null));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testGetOrDefault_absentNull() {
    assertEquals(
        "getOrDefault(null, def) should return the default value",
        v3(),
        getMap().getOrDefault(null, v3()));

            

Reported by PMD.

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

Line: 73

                  assertEquals(
        "getOrDefault(null, def) should return the default value",
        v3(),
        getMap().getOrDefault(null, v3()));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
  public void testGetOrDefault_nullAbsentAndUnsupported() {
    try {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/ForMapMultimapAsMapImplementsMapTest.java
24 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 40

                @Override
  protected Map<String, Collection<Integer>> makeEmptyMap() {
    Map<String, Integer> map = Maps.newHashMap();
    return Multimaps.forMap(map).asMap();
  }

  @Override
  protected Map<String, Collection<Integer>> makePopulatedMap() {
    Map<String, Integer> map = Maps.newHashMap();

            

Reported by PMD.

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

Line: 46

                @Override
  protected Map<String, Collection<Integer>> makePopulatedMap() {
    Map<String, Integer> map = Maps.newHashMap();
    map.put("foo", 1);
    map.put("bar", 2);
    map.put("cow", 3);
    return Multimaps.forMap(map).asMap();
  }


            

Reported by PMD.

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

Line: 47

                protected Map<String, Collection<Integer>> makePopulatedMap() {
    Map<String, Integer> map = Maps.newHashMap();
    map.put("foo", 1);
    map.put("bar", 2);
    map.put("cow", 3);
    return Multimaps.forMap(map).asMap();
  }

  @Override

            

Reported by PMD.

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

Line: 48

                  Map<String, Integer> map = Maps.newHashMap();
    map.put("foo", 1);
    map.put("bar", 2);
    map.put("cow", 3);
    return Multimaps.forMap(map).asMap();
  }

  @Override
  public void testEntrySetRemoveAllNullFromEmpty() {

            

Reported by PMD.

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

Line: 49

                  map.put("foo", 1);
    map.put("bar", 2);
    map.put("cow", 3);
    return Multimaps.forMap(map).asMap();
  }

  @Override
  public void testEntrySetRemoveAllNullFromEmpty() {
    try {

            

Reported by PMD.

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

Line: 52

                  return Multimaps.forMap(map).asMap();
  }

  @Override
  public void testEntrySetRemoveAllNullFromEmpty() {
    try {
      super.testEntrySetRemoveAllNullFromEmpty();
    } catch (RuntimeException tolerated) {
      // GWT's HashMap.entrySet().removeAll(null) doesn't throws NPE.

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 56

                public void testEntrySetRemoveAllNullFromEmpty() {
    try {
      super.testEntrySetRemoveAllNullFromEmpty();
    } catch (RuntimeException tolerated) {
      // GWT's HashMap.entrySet().removeAll(null) doesn't throws NPE.
    }
  }

  @Override

            

Reported by PMD.

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

Line: 56

                public void testEntrySetRemoveAllNullFromEmpty() {
    try {
      super.testEntrySetRemoveAllNullFromEmpty();
    } catch (RuntimeException tolerated) {
      // GWT's HashMap.entrySet().removeAll(null) doesn't throws NPE.
    }
  }

  @Override

            

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

                  }
  }

  @Override
  public void testEntrySetRetainAllNullFromEmpty() {
    try {
      super.testEntrySetRetainAllNullFromEmpty();
    } catch (RuntimeException tolerated) {
      // GWT's HashMap.entrySet().retainAll(null) doesn't throws NPE.

            

Reported by PMD.

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

Line: 65

                public void testEntrySetRetainAllNullFromEmpty() {
    try {
      super.testEntrySetRetainAllNullFromEmpty();
    } catch (RuntimeException tolerated) {
      // GWT's HashMap.entrySet().retainAll(null) doesn't throws NPE.
    }
  }

  @Override

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapComputeIfPresentTester.java
24 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: 43

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapComputeIfPresentTester<K, V> extends AbstractMapTester<K, V> {

  @MapFeature.Require(SUPPORTS_PUT)
  public void testComputeIfPresent_supportedAbsent() {
    assertNull(
        "computeIfPresent(notPresent, function) should return null",
        getMap()
            .computeIfPresent(

            

Reported by PMD.

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

Line: 47

                public void testComputeIfPresent_supportedAbsent() {
    assertNull(
        "computeIfPresent(notPresent, function) should return null",
        getMap()
            .computeIfPresent(
                k3(),
                (k, v) -> {
                  throw new AssertionFailedError();
                }));

            

Reported by PMD.

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

Line: 56

                  expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfPresent_supportedPresent() {
    assertEquals(
        "computeIfPresent(present, function) should return new value",
        v3(),

            

Reported by PMD.

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

Line: 58

              
  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfPresent_supportedPresent() {
    assertEquals(
        "computeIfPresent(present, function) should return new value",
        v3(),
        getMap()
            .computeIfPresent(

            

Reported by PMD.

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

Line: 62

                  assertEquals(
        "computeIfPresent(present, function) should return new value",
        v3(),
        getMap()
            .computeIfPresent(
                k0(),
                (k, v) -> {
                  assertEquals(k0(), k);
                  assertEquals(v0(), v);

            

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

                  expectReplacement(entry(k0(), v3()));
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfPresent_functionReturnsNull() {
    assertNull(
        "computeIfPresent(present, returnsNull) should return null",
        getMap()

            

Reported by PMD.

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

Line: 75

              
  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfPresent_functionReturnsNull() {
    assertNull(
        "computeIfPresent(present, returnsNull) should return null",
        getMap()
            .computeIfPresent(
                k0(),

            

Reported by PMD.

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

Line: 78

                public void testComputeIfPresent_functionReturnsNull() {
    assertNull(
        "computeIfPresent(present, returnsNull) should return null",
        getMap()
            .computeIfPresent(
                k0(),
                (k, v) -> {
                  assertEquals(k0(), k);
                  assertEquals(v0(), v);

            

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

                  expectMissing(e0());
  }

  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfPresent_nullTreatedAsAbsent() {
    initMapWithNullValue();
    assertNull(
        "computeIfPresent(presentAssignedToNull, function) should return null",

            

Reported by PMD.

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

Line: 95

                  initMapWithNullValue();
    assertNull(
        "computeIfPresent(presentAssignedToNull, function) should return null",
        getMap()
            .computeIfPresent(
                getKeyForNullValue(),
                (k, v) -> {
                  throw new AssertionFailedError();
                }));

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java
24 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(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListSetTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_SET)
  @CollectionSize.Require(absent = ZERO)
  public void testSet() {
    doTestSet(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: 47

                  doTestSet(e3());
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @ListFeature.Require(SUPPORTS_SET)
  public void testSet_null() {
    doTestSet(null);
  }

            

Reported by PMD.

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

Line: 54

                  doTestSet(null);
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @ListFeature.Require(SUPPORTS_SET)
  public void testSet_replacingNull() {
    E[] elements = createSamplesArray();
    int i = aValidIndex();

            

Reported by PMD.

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

Line: 60

                public void testSet_replacingNull() {
    E[] elements = createSamplesArray();
    int i = aValidIndex();
    elements[i] = null;
    collection = getSubjectGenerator().create(elements);

    doTestSet(e3());
  }


            

Reported by PMD.

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

Line: 61

                  E[] elements = createSamplesArray();
    int i = aValidIndex();
    elements[i] = null;
    collection = getSubjectGenerator().create(elements);

    doTestSet(e3());
  }

  private void doTestSet(E newValue) {

            

Reported by PMD.

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

Line: 68

              
  private void doTestSet(E newValue) {
    int index = aValidIndex();
    E initialValue = getList().get(index);
    assertEquals(
        "set(i, x) should return the old element at position i.",
        initialValue,
        getList().set(index, newValue));
    assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index));

            

Reported by PMD.

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

Line: 72

                  assertEquals(
        "set(i, x) should return the old element at position i.",
        initialValue,
        getList().set(index, newValue));
    assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index));
    assertEquals("set() should not change the size of a list.", getNumElements(), getList().size());
  }

  @ListFeature.Require(SUPPORTS_SET)

            

Reported by PMD.

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

Line: 73

                      "set(i, x) should return the old element at position i.",
        initialValue,
        getList().set(index, newValue));
    assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index));
    assertEquals("set() should not change the size of a list.", getNumElements(), getList().size());
  }

  @ListFeature.Require(SUPPORTS_SET)
  public void testSet_indexTooLow() {

            

Reported by PMD.

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

Line: 74

                      initialValue,
        getList().set(index, newValue));
    assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index));
    assertEquals("set() should not change the size of a list.", getNumElements(), getList().size());
  }

  @ListFeature.Require(SUPPORTS_SET)
  public void testSet_indexTooLow() {
    try {

            

Reported by PMD.

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

Line: 77

                  assertEquals("set() should not change the size of a list.", getNumElements(), getList().size());
  }

  @ListFeature.Require(SUPPORTS_SET)
  public void testSet_indexTooLow() {
    try {
      getList().set(-1, e3());
      fail("set(-1) should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {

            

Reported by PMD.

android/guava/src/com/google/common/collect/Iterables.java
24 issues
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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkRemove;


            

Reported by PMD.

Avoid really long classes.
Design

Line: 66

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

  /** Returns an unmodifiable view of {@code iterable}. */
  public static <T extends @Nullable Object> Iterable<T> unmodifiableIterable(
      final Iterable<? extends T> iterable) {

            

Reported by PMD.

Possible God Class (WMC=87, ATFD=21, TCC=0.000%)
Design

Line: 66

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

  /** Returns an unmodifiable view of {@code iterable}. */
  public static <T extends @Nullable Object> Iterable<T> unmodifiableIterable(
      final Iterable<? extends T> iterable) {

            

Reported by PMD.

The class 'Iterables' has a total cyclomatic complexity of 87 (highest 6).
Design

Line: 66

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

  /** Returns an unmodifiable view of {@code iterable}. */
  public static <T extends @Nullable Object> Iterable<T> unmodifiableIterable(
      final Iterable<? extends T> iterable) {

            

Reported by PMD.

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

Line: 66

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

  /** Returns an unmodifiable view of {@code iterable}. */
  public static <T extends @Nullable Object> Iterable<T> unmodifiableIterable(
      final Iterable<? extends T> iterable) {

            

Reported by PMD.

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

Line: 94

              
  private static final class UnmodifiableIterable<T extends @Nullable Object>
      extends FluentIterable<T> {
    private final Iterable<? extends T> iterable;

    private UnmodifiableIterable(Iterable<? extends T> iterable) {
      this.iterable = iterable;
    }


            

Reported by PMD.

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

Line: 219

                  }

    // Clear the tail of any remaining items
    list.subList(to, list.size()).clear();
    return from != to;
  }

  private static <T extends @Nullable Object> void slowRemoveIfForRemainingElements(
      List<T> list, Predicate<? super T> predicate, int to, int from) {

            

Reported by PMD.

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

Line: 272

                  if (iterable1 instanceof Collection && iterable2 instanceof Collection) {
      Collection<?> collection1 = (Collection<?>) iterable1;
      Collection<?> collection2 = (Collection<?>) iterable2;
      if (collection1.size() != collection2.size()) {
        return false;
      }
    }
    return Iterators.elementsEqual(iterable1.iterator(), iterable2.iterator());
  }

            

Reported by PMD.

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

Line: 272

                  if (iterable1 instanceof Collection && iterable2 instanceof Collection) {
      Collection<?> collection1 = (Collection<?>) iterable1;
      Collection<?> collection2 = (Collection<?>) iterable2;
      if (collection1.size() != collection2.size()) {
        return false;
      }
    }
    return Iterators.elementsEqual(iterable1.iterator(), iterable2.iterator());
  }

            

Reported by PMD.

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

Line: 338

              
  static <T extends @Nullable Object> T[] toArray(Iterable<? extends T> iterable, T[] array) {
    Collection<? extends T> collection = castOrCopyToCollection(iterable);
    return collection.toArray(array);
  }

  /**
   * Copies an iterable's elements into an array.
   *

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/ListMultimapRemoveTester.java
24 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 ListMultimapRemoveTester<K, V> extends AbstractListMultimapTester<K, V> {
  @SuppressWarnings("unchecked")
  @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(SEVERAL)
  public void testMultimapRemoveDeletesFirstOccurrence() {
    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));


            

Reported by PMD.

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

Line: 41

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListMultimapRemoveTester<K, V> extends AbstractListMultimapTester<K, V> {
  @SuppressWarnings("unchecked")
  @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(SEVERAL)
  public void testMultimapRemoveDeletesFirstOccurrence() {
    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));


            

Reported by PMD.

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

Line: 47

                public void testMultimapRemoveDeletesFirstOccurrence() {
    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));

    List<V> list = multimap().get(k0());
    multimap().remove(k0(), v0());
    assertContentsInOrder(list, v1(), v0());
  }

  @SuppressWarnings("unchecked")

            

Reported by PMD.

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

Line: 48

                  resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));

    List<V> list = multimap().get(k0());
    multimap().remove(k0(), v0());
    assertContentsInOrder(list, v1(), v0());
  }

  @SuppressWarnings("unchecked")
  @MapFeature.Require(SUPPORTS_REMOVE)

            

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

                  assertContentsInOrder(list, v1(), v0());
  }

  @SuppressWarnings("unchecked")
  @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(SEVERAL)
  public void testRemoveAtIndexFromGetPropagates() {
    List<V> values = Arrays.asList(v0(), v1(), v0());


            

Reported by PMD.

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

Line: 62

                    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));
      List<V> expectedValues = copyToList(values);

      multimap().get(k0()).remove(i);
      expectedValues.remove(i);

      assertGet(k0(), expectedValues);
    }
  }

            

Reported by PMD.

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

Line: 62

                    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));
      List<V> expectedValues = copyToList(values);

      multimap().get(k0()).remove(i);
      expectedValues.remove(i);

      assertGet(k0(), expectedValues);
    }
  }

            

Reported by PMD.

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

Line: 63

                    List<V> expectedValues = copyToList(values);

      multimap().get(k0()).remove(i);
      expectedValues.remove(i);

      assertGet(k0(), expectedValues);
    }
  }


            

Reported by PMD.

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

Line: 69

                  }
  }

  @SuppressWarnings("unchecked")
  @MapFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(SEVERAL)
  public void testRemoveAtIndexFromAsMapPropagates() {
    List<V> values = Arrays.asList(v0(), v1(), v0());


            

Reported by PMD.

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

Line: 79

                    resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v0()));
      List<V> expectedValues = copyToList(values);

      List<V> asMapValue = (List<V>) multimap().asMap().get(k0());
      asMapValue.remove(i);
      expectedValues.remove(i);

      assertGet(k0(), expectedValues);
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/primitives/PrimitivesTest.java
24 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 30

               * @author Kevin Bourrillion
 */
public class PrimitivesTest extends TestCase {
  public void testIsWrapperType() {
    assertTrue(Primitives.isWrapperType(Void.class));
    assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {

            

Reported by PMD.

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

Line: 30

               * @author Kevin Bourrillion
 */
public class PrimitivesTest extends TestCase {
  public void testIsWrapperType() {
    assertTrue(Primitives.isWrapperType(Void.class));
    assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

               */
public class PrimitivesTest extends TestCase {
  public void testIsWrapperType() {
    assertTrue(Primitives.isWrapperType(Void.class));
    assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

              public class PrimitivesTest extends TestCase {
  public void testIsWrapperType() {
    assertTrue(Primitives.isWrapperType(Void.class));
    assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.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: 35

                  assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.class));
    assertSame(String.class, Primitives.wrap(String.class));
  }


            

Reported by PMD.

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

Line: 35

                  assertFalse(Primitives.isWrapperType(void.class));
  }

  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.class));
    assertSame(String.class, Primitives.wrap(String.class));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                }

  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.class));
    assertSame(String.class, Primitives.wrap(String.class));
  }

  public void testUnwrap() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 37

              
  public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.class));
    assertSame(String.class, Primitives.wrap(String.class));
  }

  public void testUnwrap() {
    assertSame(int.class, Primitives.unwrap(Integer.class));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

                public void testWrap() {
    assertSame(Integer.class, Primitives.wrap(int.class));
    assertSame(Integer.class, Primitives.wrap(Integer.class));
    assertSame(String.class, Primitives.wrap(String.class));
  }

  public void testUnwrap() {
    assertSame(int.class, Primitives.unwrap(Integer.class));
    assertSame(int.class, Primitives.unwrap(int.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: 41

                  assertSame(String.class, Primitives.wrap(String.class));
  }

  public void testUnwrap() {
    assertSame(int.class, Primitives.unwrap(Integer.class));
    assertSame(int.class, Primitives.unwrap(int.class));
    assertSame(String.class, Primitives.unwrap(String.class));
  }


            

Reported by PMD.

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

Line: 43

               */
@GwtCompatible(serializable = true, emulated = true)
@ElementTypesAreNonnullByDefault
class ObjectCountHashMap<K extends @Nullable Object> {

  /** Creates an empty {@code ObjectCountHashMap} instance. */
  static <K extends @Nullable Object> ObjectCountHashMap<K> create() {
    return new ObjectCountHashMap<K>();
  }

            

Reported by PMD.

Field size has the same name as a method
Error

Line: 90

                /** The values of the entries in the map. */
  transient int[] values;

  transient int size;

  transient int modCount;

  /**
   * The hashtable. Its values are indexes to the keys, values, and entries arrays.

            

Reported by PMD.

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

Line: 189

                  return size;
  }

  @SuppressWarnings("unchecked")
  @ParametricNullness
  K getKey(int index) {
    checkElementIndex(index, size);
    return (K) keys[index];
  }

            

Reported by PMD.

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

Line: 212

                }

  class MapEntry extends AbstractEntry<K> {
    @ParametricNullness final K key;

    int lastKnownIndex;

    @SuppressWarnings("unchecked") // keys only contains Ks
    MapEntry(int index) {

            

Reported by PMD.

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

Line: 214

                class MapEntry extends AbstractEntry<K> {
    @ParametricNullness final K key;

    int lastKnownIndex;

    @SuppressWarnings("unchecked") // keys only contains Ks
    MapEntry(int index) {
      this.key = (K) keys[index];
      this.lastKnownIndex = index;

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 425

                  int last = UNSET;
    do {
      if (getHash(entries[next]) == hash) {
        if (Objects.equal(key, keys[next])) {
          int oldValue = values[next];

          if (last == UNSET) {
            // we need to update the root link from table[]
            table[tableIndex] = getNext(entries[next]);

            

Reported by PMD.

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

Line: 462

                    // move last entry to deleted spot
      keys[dstIndex] = keys[srcIndex];
      values[dstIndex] = values[srcIndex];
      keys[srcIndex] = null;
      values[srcIndex] = 0;

      // move the last entry to the removed spot, just like we moved the element
      long lastEntry = entries[srcIndex];
      entries[dstIndex] = lastEntry;

            

Reported by PMD.

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

Line: 489

                      entries[previous] = swapNext(entry, dstIndex);
      }
    } else {
      keys[dstIndex] = null;
      values[dstIndex] = 0;
      entries[dstIndex] = UNSET;
    }
  }


            

Reported by PMD.

Found 'DU'-anomaly for variable 'entries' (lines '285'-'323').
Error

Line: 285

                @CanIgnoreReturnValue
  public int put(@ParametricNullness K key, int value) {
    checkPositive(value, "count");
    long[] entries = this.entries;
    @Nullable Object[] keys = this.keys;
    int[] values = this.values;

    int hash = smearedHash(key);
    int tableIndex = hash & hashTableMask();

            

Reported by PMD.

Found 'DU'-anomaly for variable 'keys' (lines '286'-'323').
Error

Line: 286

                public int put(@ParametricNullness K key, int value) {
    checkPositive(value, "count");
    long[] entries = this.entries;
    @Nullable Object[] keys = this.keys;
    int[] values = this.values;

    int hash = smearedHash(key);
    int tableIndex = hash & hashTableMask();
    int newEntryIndex = this.size; // current size, and pointer to the entry to be appended

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/FuturesGetChecked.java
24 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 61

                  try {
      return future.get();
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }

            

Reported by PMD.

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

Line: 65

                    throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }
  }

  /** Implementation of {@link Futures#getChecked(Future, Class, long, TimeUnit)}. */
  @CanIgnoreReturnValue

            

Reported by PMD.

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

Line: 75

                static <V extends @Nullable Object, X extends Exception> V getChecked(
      Future<V> future, Class<X> exceptionClass, long timeout, TimeUnit unit) throws X {
    // TODO(cpovirk): benchmark a version of this method that accepts a GetCheckedTypeValidator
    bestGetCheckedTypeValidator().validateClass(exceptionClass);
    try {
      return future.get(timeout, unit);
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);

            

Reported by PMD.

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

Line: 79

                  try {
      return future.get(timeout, unit);
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);
    } catch (TimeoutException e) {
      throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);

            

Reported by PMD.

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

Line: 85

                    throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }
  }

  @VisibleForTesting
  interface GetCheckedTypeValidator {

            

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

                 * <p>Uses reflection to gracefully fall back to when certain implementations aren't available.
   */
  @VisibleForTesting
  static class GetCheckedTypeValidatorHolder {
    static final GetCheckedTypeValidator BEST_VALIDATOR = getBestValidator();

    enum WeakSetValidator implements GetCheckedTypeValidator {
      INSTANCE;


            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 146

                       * Ideally we'd have a real eviction policy, but until we see a problem in practice, I hope
         * that this will suffice. I have not even benchmarked with different size limits.
         */
        if (validClasses.size() > 1000) {
          validClasses.clear();
        }

        validClasses.add(new WeakReference<Class<? extends Exception>>(exceptionClass));
      }

            

Reported by PMD.

Avoid unused local variables such as 'unused'.
Design

Line: 183

                private static boolean hasConstructorUsableByGetChecked(
      Class<? extends Exception> exceptionClass) {
    try {
      Exception unused = newWithCause(exceptionClass, new Exception());
      return true;
    } catch (Exception e) {
      return false;
    }
  }

            

Reported by PMD.

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

Line: 185

                  try {
      Exception unused = newWithCause(exceptionClass, new Exception());
      return true;
    } catch (Exception e) {
      return false;
    }
  }

  private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) {

            

Reported by PMD.

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

Line: 197

                  for (Constructor<X> constructor : preferringStrings(constructors)) {
      X instance = newFromConstructor(constructor, cause);
      if (instance != null) {
        if (instance.getCause() == null) {
          instance.initCause(cause);
        }
        return instance;
      }
    }

            

Reported by PMD.