The following issues were found

guava-tests/benchmark/com/google/common/hash/HashCodeBenchmark.java
12 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 50

                private static final Random random = new Random(42);

  @Param({"1000", "100000"})
  private int size;

  @Param WhereToDiffer whereToDiffer;

  @Param EqualsImplementation equalsImpl;


            

Reported by PMD.

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

Line: 52

                @Param({"1000", "100000"})
  private int size;

  @Param WhereToDiffer whereToDiffer;

  @Param EqualsImplementation equalsImpl;

  private enum WhereToDiffer {
    ONE_PERCENT_IN,

            

Reported by PMD.

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

Line: 54

              
  @Param WhereToDiffer whereToDiffer;

  @Param EqualsImplementation equalsImpl;

  private enum WhereToDiffer {
    ONE_PERCENT_IN,
    LAST_BYTE,
    NOT_AT_ALL;

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 66

                  ANDING_BOOLEANS {
      @Override
      boolean doEquals(byte[] a, byte[] b) {
        if (a.length != b.length) {
          return false;
        }
        boolean areEqual = true;
        for (int i = 0; i < a.length; i++) {
          areEqual &= (a[i] == b[i]);

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 79

                  XORING_TO_BYTE {
      @Override
      boolean doEquals(byte[] a, byte[] b) {
        if (a.length != b.length) {
          return false;
        }
        byte result = 0;
        for (int i = 0; i < a.length; i++) {
          result = (byte) (result | a[i] ^ b[i]);

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 92

                  XORING_TO_INT {
      @Override
      boolean doEquals(byte[] a, byte[] b) {
        if (a.length != b.length) {
          return false;
        }
        int result = 0;
        for (int i = 0; i < a.length; i++) {
          result |= a[i] ^ b[i];

            

Reported by PMD.

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

Line: 118

                  abstract boolean doEquals(byte[] a, byte[] b);
  }

  private byte[] testBytesA;
  private byte[] testBytesB;

  @BeforeExperiment
  void setUp() {
    testBytesA = new byte[size];

            

Reported by PMD.

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

Line: 119

                }

  private byte[] testBytesA;
  private byte[] testBytesB;

  @BeforeExperiment
  void setUp() {
    testBytesA = new byte[size];
    random.nextBytes(testBytesA);

            

Reported by PMD.

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

Line: 121

                private byte[] testBytesA;
  private byte[] testBytesB;

  @BeforeExperiment
  void setUp() {
    testBytesA = new byte[size];
    random.nextBytes(testBytesA);
    testBytesB = Arrays.copyOf(testBytesA, size);
    int indexToDifferAt = -1;

            

Reported by PMD.

Switch statements should have a default label
Design

Line: 127

                  random.nextBytes(testBytesA);
    testBytesB = Arrays.copyOf(testBytesA, size);
    int indexToDifferAt = -1;
    switch (whereToDiffer) {
      case ONE_PERCENT_IN:
        indexToDifferAt = (int) (size * 0.01);
        break;
      case LAST_BYTE:
        indexToDifferAt = size - 1;

            

Reported by PMD.

guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java
12 issues
Avoid unused local variables such as 'mutex'.
Design

Line: 82

                public static final class SynchronizedHashBiMapGenerator extends TestStringBiMapGenerator {
    @Override
    protected BiMap<String, String> create(Entry<String, String>[] entries) {
      Object mutex = new Object();
      BiMap<String, String> result = HashBiMap.create();
      for (Entry<String, String> entry : entries) {
        checkArgument(!result.containsKey(entry.getKey()));
        result.put(entry.getKey(), entry.getValue());
      }

            

Reported by PMD.

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

Line: 107

                }

  static class TestBiMap<K, V> extends TestMap<K, V> implements BiMap<K, V> {
    private final BiMap<K, V> delegate;

    public TestBiMap(BiMap<K, V> delegate, Object mutex) {
      super(delegate, mutex);
      this.delegate = delegate;
    }

            

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

                  private static final long serialVersionUID = 0;
  }

  public void testForcePut() {
    create().forcePut(null, null);
  }

  public void testInverse() {
    BiMap<String, Integer> bimap = create();

            

Reported by PMD.

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

Line: 142

                }

  public void testForcePut() {
    create().forcePut(null, null);
  }

  public void testInverse() {
    BiMap<String, Integer> bimap = create();
    BiMap<Integer, String> inverse = bimap.inverse();

            

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

                  create().forcePut(null, null);
  }

  public void testInverse() {
    BiMap<String, Integer> bimap = create();
    BiMap<Integer, String> inverse = bimap.inverse();
    assertSame(bimap, inverse.inverse());
    assertTrue(inverse instanceof SynchronizedBiMap);
    assertSame(mutex, ((SynchronizedBiMap<?, ?>) inverse).mutex);

            

Reported by PMD.

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

Line: 145

                  create().forcePut(null, null);
  }

  public void testInverse() {
    BiMap<String, Integer> bimap = create();
    BiMap<Integer, String> inverse = bimap.inverse();
    assertSame(bimap, inverse.inverse());
    assertTrue(inverse instanceof SynchronizedBiMap);
    assertSame(mutex, ((SynchronizedBiMap<?, ?>) inverse).mutex);

            

Reported by PMD.

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

Line: 147

              
  public void testInverse() {
    BiMap<String, Integer> bimap = create();
    BiMap<Integer, String> inverse = bimap.inverse();
    assertSame(bimap, inverse.inverse());
    assertTrue(inverse instanceof SynchronizedBiMap);
    assertSame(mutex, ((SynchronizedBiMap<?, ?>) inverse).mutex);
  }


            

Reported by PMD.

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

Line: 148

                public void testInverse() {
    BiMap<String, Integer> bimap = create();
    BiMap<Integer, String> inverse = bimap.inverse();
    assertSame(bimap, inverse.inverse());
    assertTrue(inverse instanceof SynchronizedBiMap);
    assertSame(mutex, ((SynchronizedBiMap<?, ?>) inverse).mutex);
  }

  @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: 153

                  assertSame(mutex, ((SynchronizedBiMap<?, ?>) inverse).mutex);
  }

  @Override
  public void testValues() {
    BiMap<String, Integer> map = create();
    Set<Integer> values = map.values();
    assertTrue(values instanceof SynchronizedSet);
    assertSame(mutex, ((SynchronizedSet<?>) values).mutex);

            

Reported by PMD.

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

Line: 154

                }

  @Override
  public void testValues() {
    BiMap<String, Integer> map = create();
    Set<Integer> values = map.values();
    assertTrue(values instanceof SynchronizedSet);
    assertSame(mutex, ((SynchronizedSet<?>) values).mutex);
  }

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultisetSetCountConditionallyTester.java
12 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 51

                }

  private boolean setCount(E element, int count) {
    return getMultiset().setCount(element, getMultiset().count(element), count);
  }

  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);

            

Reported by PMD.

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

Line: 51

                }

  private boolean setCount(E element, int count) {
    return getMultiset().setCount(element, getMultiset().count(element), count);
  }

  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);

            

Reported by PMD.

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

Line: 56

              
  private void assertSetCountNegativeOldCount() {
    try {
      getMultiset().setCount(e3(), -1, 1);
      fail("calling setCount() with a negative oldCount should throw IllegalArgumentException");
    } catch (IllegalArgumentException 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: 64

              
  // Negative oldCount.

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_negativeOldCount_addSupported() {
    assertSetCountNegativeOldCount();
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)

            

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

                  assertSetCountNegativeOldCount();
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testSetCountConditional_negativeOldCount_addUnsupported() {
    try {
      assertSetCountNegativeOldCount();
    } catch (UnsupportedOperationException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 73

                public void testSetCountConditional_negativeOldCount_addUnsupported() {
    try {
      assertSetCountNegativeOldCount();
    } catch (UnsupportedOperationException tolerated) {
    }
  }

  // Incorrect expected present count.


            

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

              
  // Incorrect expected present count.

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_oldCountTooLarge() {
    assertFalse(
        "setCount() with a too-large oldCount should return false",
        getMultiset().setCount(e0(), 2, 3));
    expectUnchanged();

            

Reported by PMD.

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

Line: 83

                public void testSetCountConditional_oldCountTooLarge() {
    assertFalse(
        "setCount() with a too-large oldCount should return false",
        getMultiset().setCount(e0(), 2, 3));
    expectUnchanged();
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_ADD)

            

Reported by PMD.

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

Line: 87

                  expectUnchanged();
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testSetCountConditional_oldCountTooSmallZero() {
    assertFalse(
        "setCount() with a too-small oldCount should return false",
        getMultiset().setCount(e0(), 0, 2));

            

Reported by PMD.

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

Line: 92

                public void testSetCountConditional_oldCountTooSmallZero() {
    assertFalse(
        "setCount() with a too-small oldCount should return false",
        getMultiset().setCount(e0(), 0, 2));
    expectUnchanged();
  }

  @CollectionSize.Require(SEVERAL)
  @CollectionFeature.Require(SUPPORTS_ADD)

            

Reported by PMD.

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

Line: 35

              @GwtCompatible(emulated = true)
public class TreeTraverserTest extends TestCase {
  private static class Node {
    final char value;

    Node(char value) {
      this.value = value;
    }
  }

            

Reported by PMD.

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

Line: 43

                }

  private static final class Tree extends Node {
    final List<Tree> children;

    public Tree(char value, Tree... children) {
      super(value);
      this.children = Arrays.asList(children);
    }

            

Reported by PMD.

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

Line: 97

                  return builder.toString();
  }

  public void testPreOrder() {
    assertThat(iterationOrder(ADAPTER.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

  public void testPostOrder() {
    assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");

            

Reported by PMD.

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

Line: 98

                }

  public void testPreOrder() {
    assertThat(iterationOrder(ADAPTER.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

  public void testPostOrder() {
    assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");
  }

            

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

                  assertThat(iterationOrder(ADAPTER.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

  public void testPostOrder() {
    assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");
  }

  public void testBreadthOrder() {
    assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");

            

Reported by PMD.

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

Line: 102

                }

  public void testPostOrder() {
    assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");
  }

  public void testBreadthOrder() {
    assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");
  }

            

Reported by PMD.

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

Line: 105

                  assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");
  }

  public void testBreadthOrder() {
    assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");
  }

  public void testUsing() {
    assertThat(iterationOrder(ADAPTER_USING_USING.preOrderTraversal(h))).isEqualTo("hdabcegf");

            

Reported by PMD.

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

Line: 106

                }

  public void testBreadthOrder() {
    assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");
  }

  public void testUsing() {
    assertThat(iterationOrder(ADAPTER_USING_USING.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

            

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

                  assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");
  }

  public void testUsing() {
    assertThat(iterationOrder(ADAPTER_USING_USING.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

  @GwtIncompatible // NullPointerTester
  public void testNulls() {

            

Reported by PMD.

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

Line: 110

                }

  public void testUsing() {
    assertThat(iterationOrder(ADAPTER_USING_USING.preOrderTraversal(h))).isEqualTo("hdabcegf");
  }

  @GwtIncompatible // NullPointerTester
  public void testNulls() {
    NullPointerTester tester = new NullPointerTester();

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java
12 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: 42

                /** Override to return "indexOf" or "lastIndexOf()" for use in failure messages. */
  protected abstract String getMethodName();

  @CollectionSize.Require(absent = ZERO)
  public void testFind_yes() {
    assertEquals(
        getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().get(0)));
  }


            

Reported by PMD.

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

Line: 45

                @CollectionSize.Require(absent = ZERO)
  public void testFind_yes() {
    assertEquals(
        getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().get(0)));
  }

  public void testFind_no() {
    assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(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: 48

                      getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().get(0)));
  }

  public void testFind_no() {
    assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testFind_nullNotContainedButSupported() {

            

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

                  assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testFind_nullNotContainedButSupported() {
    assertEquals(getMethodName() + "(nullNotPresent) should return -1", -1, find(null));
  }

  @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)

            

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

                  assertEquals(getMethodName() + "(nullNotPresent) should return -1", -1, find(null));
  }

  @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
  public void testFind_nullNotContainedAndUnsupported() {
    try {
      assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null));
    } catch (NullPointerException tolerated) {
    }

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 61

                public void testFind_nullNotContainedAndUnsupported() {
    try {
      assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 61

                public void testFind_nullNotContainedAndUnsupported() {
    try {
      assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 61

                public void testFind_nullNotContainedAndUnsupported() {
    try {
      assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null));
    } catch (NullPointerException tolerated) {
    }
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @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: 65

                  }
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testFind_nonNullWhenNullContained() {
    initCollectionWithNullElement();
    assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(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: 72

                  assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testFind_nullContained() {
    initCollectionWithNullElement();
    assertEquals(
        getMethodName() + "(null) should return " + getNullLocation(),

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java
12 issues
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: 41

               * @author George van den Driessche
 */
@GwtIncompatible
public class FeatureUtil {
  /** A cache of annotated objects (typically a Class or Method) to its set of annotations. */
  private static Map<AnnotatedElement, List<Annotation>> annotationCache = new HashMap<>();

  private static final Map<Class<?>, TesterRequirements> classTesterRequirementsCache =
      new HashMap<>();

            

Reported by PMD.

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

Line: 62

                  Queue<Feature<?>> queue = new ArrayDeque<>(features);
    while (!queue.isEmpty()) {
      Feature<?> feature = queue.remove();
      for (Feature<?> implied : feature.getImpliedFeatures()) {
        if (features.add(implied)) {
          queue.add(implied);
        }
      }
    }

            

Reported by PMD.

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

Line: 83

                  Queue<Feature<?>> queue = new ArrayDeque<>(features);
    while (!queue.isEmpty()) {
      Feature<?> feature = queue.remove();
      for (Feature<?> implied : feature.getImpliedFeatures()) {
        if (!features.contains(implied) && impliedSet.add(implied)) {
          queue.add(implied);
        }
      }
    }

            

Reported by PMD.

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

Line: 182

                  final Feature<?>[] presentFeatures;
    final Feature<?>[] absentFeatures;
    try {
      presentFeatures = (Feature[]) annotationClass.getMethod("value").invoke(testerAnnotation);
      absentFeatures = (Feature[]) annotationClass.getMethod("absent").invoke(testerAnnotation);
    } catch (Exception e) {
      throw new IllegalArgumentException("Error extracting features from tester annotation.", e);
    }
    Set<Feature<?>> allPresentFeatures =

            

Reported by PMD.

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

Line: 183

                  final Feature<?>[] absentFeatures;
    try {
      presentFeatures = (Feature[]) annotationClass.getMethod("value").invoke(testerAnnotation);
      absentFeatures = (Feature[]) annotationClass.getMethod("absent").invoke(testerAnnotation);
    } catch (Exception e) {
      throw new IllegalArgumentException("Error extracting features from tester annotation.", e);
    }
    Set<Feature<?>> allPresentFeatures =
        addImpliedFeatures(Helpers.<Feature<?>>copyToSet(presentFeatures));

            

Reported by PMD.

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

Line: 184

                  try {
      presentFeatures = (Feature[]) annotationClass.getMethod("value").invoke(testerAnnotation);
      absentFeatures = (Feature[]) annotationClass.getMethod("absent").invoke(testerAnnotation);
    } catch (Exception e) {
      throw new IllegalArgumentException("Error extracting features from tester annotation.", e);
    }
    Set<Feature<?>> allPresentFeatures =
        addImpliedFeatures(Helpers.<Feature<?>>copyToSet(presentFeatures));
    Set<Feature<?>> allAbsentFeatures =

            

Reported by PMD.

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

Line: 236

                    if (annotations == null) {
        annotations = new ArrayList<>();
        for (Annotation a : classOrMethod.getDeclaredAnnotations()) {
          if (a.annotationType().isAnnotationPresent(TesterAnnotation.class)) {
            annotations.add(a);
          }
        }
        annotations = Collections.unmodifiableList(annotations);
        annotationCache.put(classOrMethod, annotations);

            

Reported by PMD.

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

Line: 266

                  Set<Feature<?>> moreAbsentFeatures = moreRequirements.getAbsentFeatures();
    checkConflict("absent", absentFeatures, "present", morePresentFeatures, source);
    checkConflict("present", presentFeatures, "absent", moreAbsentFeatures, source);
    presentFeatures.addAll(morePresentFeatures);
    absentFeatures.addAll(moreAbsentFeatures);
    return requirements;
  }

  // Used by incorporateRequirements() only

            

Reported by PMD.

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

Line: 267

                  checkConflict("absent", absentFeatures, "present", morePresentFeatures, source);
    checkConflict("present", presentFeatures, "absent", moreAbsentFeatures, source);
    presentFeatures.addAll(morePresentFeatures);
    absentFeatures.addAll(moreAbsentFeatures);
    return requirements;
  }

  // Used by incorporateRequirements() only
  private static void checkConflict(

            

Reported by PMD.

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

Line: 295

                /** Construct a new {@link java.util.Set} that is the intersection of the given sets. */
  public static <T> Set<T> intersection(Set<? extends T> set1, Set<? extends T> set2) {
    Set<T> result = Helpers.<T>copyToSet(set1);
    result.retainAll(set2);
    return result;
  }
}

            

Reported by PMD.

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

Line: 45

               * @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: 46

               */
@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: 105

                  return Collections.emptySet();
  }

  public Test testsForCheckedQueue() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                Queue<String> queue = 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: 126

                      .createTestSuite();
  }

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

                      .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: 160

                      .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: 175

                      .createTestSuite();
  }

  public Test testsForConcurrentLinkedDeque() {
    return QueueTestSuiteBuilder.using(
            new TestStringQueueGenerator() {
              @Override
              public Queue<String> create(String[] elements) {
                return new ConcurrentLinkedDeque<>(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: 190

                      .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: 205

                      .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: 220

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

android/guava/src/com/google/common/io/CharSink.java
12 issues
Ensure that resources like this Writer object are closed after use
Error

Line: 95

              
    Closer closer = Closer.create();
    try {
      Writer out = closer.register(openStream());
      out.append(charSequence);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 96

                  Closer closer = Closer.create();
    try {
      Writer out = closer.register(openStream());
      out.append(charSequence);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 97

                  try {
      Writer out = closer.register(openStream());
      out.append(charSequence);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

            

Reported by PMD.

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

Line: 98

                    Writer out = closer.register(openStream());
      out.append(charSequence);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 129

              
    Closer closer = Closer.create();
    try {
      Writer out = closer.register(openBufferedStream());
      for (CharSequence line : lines) {
        out.append(line).append(lineSeparator);
      }
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {

            

Reported by PMD.

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

Line: 131

                  try {
      Writer out = closer.register(openBufferedStream());
      for (CharSequence line : lines) {
        out.append(line).append(lineSeparator);
      }
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 131

                  try {
      Writer out = closer.register(openBufferedStream());
      for (CharSequence line : lines) {
        out.append(line).append(lineSeparator);
      }
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 133

                    for (CharSequence line : lines) {
        out.append(line).append(lineSeparator);
      }
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

            

Reported by PMD.

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

Line: 134

                      out.append(line).append(lineSeparator);
      }
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 155

              
    Closer closer = Closer.create();
    try {
      Writer out = closer.register(openStream());
      long written = CharStreams.copy(readable, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);

            

Reported by PMD.

android/guava/src/com/google/common/io/ByteSink.java
12 issues
Ensure that resources like this OutputStream object are closed after use
Error

Line: 102

              
    Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {

            

Reported by PMD.

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

Line: 103

                  Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 104

                  try {
      OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

            

Reported by PMD.

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

Line: 105

                    OutputStream out = closer.register(openStream());
      out.write(bytes);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 125

              
    Closer closer = Closer.create();
    try {
      OutputStream out = closer.register(openStream());
      long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);

            

Reported by PMD.

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

Line: 127

                  try {
      OutputStream out = closer.register(openStream());
      long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();

            

Reported by PMD.

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

Line: 129

                    long written = ByteStreams.copy(input, out);
      out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330
      return written;
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }

            

Reported by PMD.

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

Line: 142

                 */
  private final class AsCharSink extends CharSink {

    private final Charset charset;

    private AsCharSink(Charset charset) {
      this.charset = checkNotNull(charset);
    }


            

Reported by PMD.

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

Line: 150

              
    @Override
    public Writer openStream() throws IOException {
      return new OutputStreamWriter(ByteSink.this.openStream(), charset);
    }

    @Override
    public String toString() {
      return ByteSink.this.toString() + ".asCharSink(" + charset + ")";

            

Reported by PMD.

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

Line: 150

              
    @Override
    public Writer openStream() throws IOException {
      return new OutputStreamWriter(ByteSink.this.openStream(), charset);
    }

    @Override
    public String toString() {
      return ByteSink.this.toString() + ".asCharSink(" + charset + ")";

            

Reported by PMD.

android/guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java
12 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 48

              
  @Override
  public HashCode hashInt(int input) {
    return hashBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(input).array());
  }

  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 53

              
  @Override
  public HashCode hashLong(long input) {
    return hashBytes(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(input).array());
  }

  @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();

            

Reported by PMD.

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

Line: 59

                @Override
  public HashCode hashUnencodedChars(CharSequence input) {
    int len = input.length();
    ByteBuffer buffer = ByteBuffer.allocate(len * 2).order(ByteOrder.LITTLE_ENDIAN);
    for (int i = 0; i < len; i++) {
      buffer.putChar(input.charAt(i));
    }
    return hashBytes(buffer.array());
  }

            

Reported by PMD.

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

Line: 63

                  for (int i = 0; i < len; i++) {
      buffer.putChar(input.charAt(i));
    }
    return hashBytes(buffer.array());
  }

  @Override
  public HashCode hashString(CharSequence input, Charset charset) {
    return hashBytes(input.toString().getBytes(charset));

            

Reported by PMD.

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

Line: 68

              
  @Override
  public HashCode hashString(CharSequence input, Charset charset) {
    return hashBytes(input.toString().getBytes(charset));
  }

  @Override
  public abstract HashCode hashBytes(byte[] input, int off, int len);


            

Reported by PMD.

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

Line: 76

              
  @Override
  public HashCode hashBytes(ByteBuffer input) {
    return newHasher(input.remaining()).putBytes(input).hash();
  }

  /** In-memory stream-based implementation of Hasher. */
  private final class BufferingHasher extends AbstractHasher {
    final ExposedByteArrayOutputStream stream;

            

Reported by PMD.