The following issues were found

android/guava-testlib/src/com/google/common/testing/NullPointerTester.java
54 issues
Avoid throwing raw exception types.
Design

Line: 368

                    error.initCause(cause);
      throw error;
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }

  private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
    ImmutableList<Parameter> params = invokable.getParameters();

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;

            

Reported by PMD.

Possible God Class (WMC=57, ATFD=61, TCC=0.985%)
Design

Line: 71

               */
@Beta
@GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

            

Reported by PMD.

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

Line: 71

               */
@Beta
@GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

            

Reported by PMD.

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

Line: 73

              @GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**

            

Reported by PMD.

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

Line: 74

              public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this

            

Reported by PMD.

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

Line: 76

                private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this
   * object.
   */

            

Reported by PMD.

Private field 'policy' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 76

                private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this
   * object.
   */

            

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

                 * Runs {@link #testConstructor} on every constructor in class {@code c} that has at least {@code
   * minimalVisibility}.
   */
  public void testConstructors(Class<?> c, Visibility minimalVisibility) {
    for (Constructor<?> constructor : c.getDeclaredConstructors()) {
      if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) {
        testConstructor(constructor);
      }
    }

            

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

                }

  /** Runs {@link #testConstructor} on every public constructor in class {@code c}. */
  public void testAllPublicConstructors(Class<?> c) {
    testConstructors(c, Visibility.PUBLIC);
  }

  /**
   * Runs {@link #testMethod} on every static method of class {@code c} that has at least {@code

            

Reported by PMD.

android/guava/src/com/google/common/collect/MinMaxPriorityQueue.java
54 issues
Using multiple unary operators may be a bug, and/or is confusing.
Error

Line: 500

              
  @VisibleForTesting
  static boolean isEvenLevel(int index) {
    int oneBased = ~~(index + 1); // for GWT
    checkState(oneBased > 0, "negative index");
    return (oneBased & EVEN_POWERS_OF_TWO) > (oneBased & ODD_POWERS_OF_TWO);
  }

  /**

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 570

                  }

    /** Bubbles a value from {@code index} up the appropriate heap if required. */
    void bubbleUp(int index, E x) {
      int crossOver = crossOverUp(index, x);

      Heap heap;
      if (crossOver == index) {
        heap = this;

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 588

                   * element ended up at.
     */
    @CanIgnoreReturnValue
    int bubbleUpAlternatingLevels(int index, E x) {
      while (index > 2) {
        int grandParentIndex = getGrandparentIndex(index);
        E e = elementData(grandParentIndex);
        if (ordering.compare(e, x) <= 0) {
          break;

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 721

                   * @return the position of the new hole (where the lowest grandchild moved from, that had no
     *     grandchild to replace it)
     */
    int fillHoleAt(int index) {
      int minGrandchildIndex;
      while ((minGrandchildIndex = findMinGrandChild(index)) > 0) {
        queue[index] = elementData(minGrandchildIndex);
        index = minGrandchildIndex;
      }

            

Reported by PMD.

Avoid reassigning parameters such as 'c'
Design

Line: 869

                   * Advances nextCursor to the index of the first element after {@code c} that is not in {@code
     * skipMe} and returns {@code size()} if there is no such element.
     */
    private void nextNotInSkipMe(int c) {
      if (nextCursor < c) {
        if (skipMe != null) {
          while (c < size() && foundAndRemovedExactReference(skipMe, elementData(c))) {
            c++;
          }

            

Reported by PMD.

Possible God Class (WMC=59, ATFD=7, TCC=9.804%)
Design

Line: 104

              @Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class MinMaxPriorityQueue<E> extends AbstractQueue<E> {

  /**
   * Creates a new min-max priority queue with default settings: natural order, no maximum size, no
   * initial contents, and an initial expected size of 11.
   */

            

Reported by PMD.

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

Line: 104

              @Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class MinMaxPriorityQueue<E> extends AbstractQueue<E> {

  /**
   * Creates a new min-max priority queue with default settings: natural order, no maximum size, no
   * initial contents, and an initial expected size of 11.
   */

            

Reported by PMD.

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

Line: 173

                   */
    private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);

            

Reported by PMD.

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

Line: 174

                  private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);
    }

            

Reported by PMD.

Field expectedSize has the same name as a method
Error

Line: 174

                  private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/reflect/ImmutableTypeToInstanceMapTest.java
54 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 43

               */
public class ImmutableTypeToInstanceMapTest extends TestCase {

  @AndroidIncompatible // problem with suite builders on Android
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ImmutableTypeToInstanceMapTest.class);

    suite.addTest(

            

Reported by PMD.

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

Line: 60

                                      ImmutableTypeToInstanceMap.builder();
                    for (Object object : elements) {
                      Entry<TypeToken, Object> entry = (Entry<TypeToken, Object>) object;
                      builder.put(entry.getKey(), entry.getValue());
                    }
                    return (Map) builder.build();
                  }
                })
            .named("ImmutableTypeToInstanceMap")

            

Reported by PMD.

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

Line: 60

                                      ImmutableTypeToInstanceMap.builder();
                    for (Object object : elements) {
                      Entry<TypeToken, Object> entry = (Entry<TypeToken, Object>) object;
                      builder.put(entry.getKey(), entry.getValue());
                    }
                    return (Map) builder.build();
                  }
                })
            .named("ImmutableTypeToInstanceMap")

            

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

                  return suite;
  }

  public void testEmpty() {
    assertEquals(0, ImmutableTypeToInstanceMap.of().size());
  }

  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 78

                }

  public void testEmpty() {
    assertEquals(0, ImmutableTypeToInstanceMap.of().size());
  }

  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()

            

Reported by PMD.

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

Line: 78

                }

  public void testEmpty() {
    assertEquals(0, ImmutableTypeToInstanceMap.of().size());
  }

  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()

            

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

                  assertEquals(0, ImmutableTypeToInstanceMap.of().size());
  }

  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()
            .put(Integer.class, 0)
            .put(int.class, 1)
            .build();

            

Reported by PMD.

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

Line: 81

                  assertEquals(0, ImmutableTypeToInstanceMap.of().size());
  }

  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()
            .put(Integer.class, 0)
            .put(int.class, 1)
            .build();

            

Reported by PMD.

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

Line: 83

              
  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()
            .put(Integer.class, 0)
            .put(int.class, 1)
            .build();
    assertEquals(2, map.size());


            

Reported by PMD.

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

Line: 83

              
  public void testPrimitiveAndWrapper() {
    ImmutableTypeToInstanceMap<Number> map =
        ImmutableTypeToInstanceMap.<Number>builder()
            .put(Integer.class, 0)
            .put(int.class, 1)
            .build();
    assertEquals(2, map.size());


            

Reported by PMD.

guava-tests/test/com/google/common/collect/TableCollectorsTest.java
54 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: 37

              public class TableCollectorsTest {

  public static final class ToImmutableTableTest extends TestCase {
    public void testToImmutableTable() {
      Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>>
          collector =
              TableCollectors.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
      BiPredicate<ImmutableTable<String, String, Integer>, ImmutableTable<String, String, Integer>>
          equivalence = pairwiseOnResultOf(ImmutableTable::cellSet);

            

Reported by PMD.

The String literal 'uno' appears 28 times in this file; the first occurrence is on line 46
Error

Line: 46

                    CollectorTester.of(collector, equivalence)
          .expectCollects(
              new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),

            

Reported by PMD.

The String literal 'one' appears 28 times in this file; the first occurrence is on line 46
Error

Line: 46

                    CollectorTester.of(collector, equivalence)
          .expectCollects(
              new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),

            

Reported by PMD.

The String literal 'two' appears 10 times in this file; the first occurrence is on line 47
Error

Line: 47

                        .expectCollects(
              new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),
              immutableCell("three", "tres", 3));

            

Reported by PMD.

The String literal 'dos' appears 10 times in this file; the first occurrence is on line 47
Error

Line: 47

                        .expectCollects(
              new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),
              immutableCell("three", "tres", 3));

            

Reported by PMD.

The String literal 'tres' appears 8 times in this file; the first occurrence is on line 48
Error

Line: 48

                            new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),
              immutableCell("three", "tres", 3));
    }

            

Reported by PMD.

The String literal 'three' appears 8 times in this file; the first occurrence is on line 48
Error

Line: 48

                            new ImmutableTable.Builder<String, String, Integer>()
                  .put("one", "uno", 1)
                  .put("two", "dos", 2)
                  .put("three", "tres", 3)
                  .build(),
              immutableCell("one", "uno", 1),
              immutableCell("two", "dos", 2),
              immutableCell("three", "tres", 3));
    }

            

Reported by PMD.

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

Line: 55

                            immutableCell("three", "tres", 3));
    }

    public void testToImmutableTableConflict() {
      Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>>
          collector =
              TableCollectors.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
      try {
        Stream.of(immutableCell("one", "uno", 1), immutableCell("one", "uno", 2))

            

Reported by PMD.

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

Line: 60

                        collector =
              TableCollectors.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
      try {
        Stream.of(immutableCell("one", "uno", 1), immutableCell("one", "uno", 2))
            .collect(collector);
        fail("Expected 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: 67

                    }
    }

    public void testToImmutableTableNullRowKey() {
      Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>>
          collector =
              TableCollectors.toImmutableTable(t -> null, Cell::getColumnKey, Cell::getValue);
      try {
        Stream.of(immutableCell("one", "uno", 1)).collect(collector);

            

Reported by PMD.

guava-tests/test/com/google/common/primitives/SignedBytesTest.java
54 issues
Avoid reassigning parameters such as 'input'
Design

Line: 164

                  testSortDescending(new byte[] {-1, 1, -2, 2}, new byte[] {2, 1, -1, -2});
  }

  private static void testSortDescending(byte[] input, byte[] expectedOutput) {
    input = Arrays.copyOf(input, input.length);
    SignedBytes.sortDescending(input);
    assertTrue(Arrays.equals(expectedOutput, input));
  }


            

Reported by PMD.

Avoid reassigning parameters such as 'input'
Design

Line: 171

                }

  private static void testSortDescending(
      byte[] input, int fromIndex, int toIndex, byte[] expectedOutput) {
    input = Arrays.copyOf(input, input.length);
    SignedBytes.sortDescending(input, fromIndex, toIndex);
    assertTrue(Arrays.equals(expectedOutput, input));
  }


            

Reported by PMD.

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

Line: 36

               */
@GwtCompatible(emulated = true)
@SuppressWarnings("cast") // redundant casts are intentional and harmless
public class SignedBytesTest extends TestCase {
  private static final byte[] EMPTY = {};
  private static final byte[] ARRAY1 = {(byte) 1};

  private static final byte LEAST = Byte.MIN_VALUE;
  private static final byte GREATEST = Byte.MAX_VALUE;

            

Reported by PMD.

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

Line: 45

              
  private static final byte[] VALUES = {LEAST, -1, 0, 1, GREATEST};

  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);

            

Reported by PMD.

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

Line: 45

              
  private static final byte[] VALUES = {LEAST, -1, 0, 1, GREATEST};

  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

              
  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);
    assertCastFails(Long.MAX_VALUE);
    assertCastFails(Long.MIN_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: 55

                  assertCastFails(Long.MIN_VALUE);
  }

  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));

            

Reported by PMD.

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

Line: 55

                  assertCastFails(Long.MIN_VALUE);
  }

  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 57

              
  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));
    assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE));
    assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 59

                  for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));
    assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE));
    assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE));
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/primitives/SignedBytesTest.java
54 issues
Avoid reassigning parameters such as 'input'
Design

Line: 164

                  testSortDescending(new byte[] {-1, 1, -2, 2}, new byte[] {2, 1, -1, -2});
  }

  private static void testSortDescending(byte[] input, byte[] expectedOutput) {
    input = Arrays.copyOf(input, input.length);
    SignedBytes.sortDescending(input);
    assertTrue(Arrays.equals(expectedOutput, input));
  }


            

Reported by PMD.

Avoid reassigning parameters such as 'input'
Design

Line: 171

                }

  private static void testSortDescending(
      byte[] input, int fromIndex, int toIndex, byte[] expectedOutput) {
    input = Arrays.copyOf(input, input.length);
    SignedBytes.sortDescending(input, fromIndex, toIndex);
    assertTrue(Arrays.equals(expectedOutput, input));
  }


            

Reported by PMD.

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

Line: 36

               */
@GwtCompatible(emulated = true)
@SuppressWarnings("cast") // redundant casts are intentional and harmless
public class SignedBytesTest extends TestCase {
  private static final byte[] EMPTY = {};
  private static final byte[] ARRAY1 = {(byte) 1};

  private static final byte LEAST = Byte.MIN_VALUE;
  private static final byte GREATEST = Byte.MAX_VALUE;

            

Reported by PMD.

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

Line: 45

              
  private static final byte[] VALUES = {LEAST, -1, 0, 1, GREATEST};

  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);

            

Reported by PMD.

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

Line: 45

              
  private static final byte[] VALUES = {LEAST, -1, 0, 1, GREATEST};

  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

              
  public void testCheckedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.checkedCast((long) value));
    }
    assertCastFails(GREATEST + 1L);
    assertCastFails(LEAST - 1L);
    assertCastFails(Long.MAX_VALUE);
    assertCastFails(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 55

                  assertCastFails(Long.MIN_VALUE);
  }

  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));

            

Reported by PMD.

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

Line: 55

                  assertCastFails(Long.MIN_VALUE);
  }

  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 57

              
  public void testSaturatedCast() {
    for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));
    assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE));
    assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 59

                  for (byte value : VALUES) {
      assertEquals(value, SignedBytes.saturatedCast((long) value));
    }
    assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L));
    assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L));
    assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE));
    assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE));
  }


            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java
54 issues
JUnit tests should include assert() or fail()
Design

Line: 38

               */
@GwtCompatible(emulated = true)
public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

            

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

               */
@GwtCompatible(emulated = true)
public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

            

Reported by PMD.

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

Line: 40

              public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

  public void testExecutorSuccess() {

            

Reported by PMD.

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

Line: 42

                  SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

  public void testExecutorSuccess() {
    CountingSameThreadExecutor ex = new CountingSameThreadExecutor();
    SettableFuture<String> f = SettableFuture.create();

            

Reported by PMD.

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

Line: 45

                  f.set("foo");
  }

  public void testExecutorSuccess() {
    CountingSameThreadExecutor ex = new CountingSameThreadExecutor();
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");

            

Reported by PMD.

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

Line: 50

                  SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");
    assertEquals(1, ex.runCount);
  }

  // Error cases
  public void testSameThreadExecutionException() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                  MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");
    assertEquals(1, ex.runCount);
  }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();

            

Reported by PMD.

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

Line: 55

                }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();
    Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);

            

Reported by PMD.

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

Line: 55

                }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();
    Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);

            

Reported by PMD.

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

Line: 60

                  Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);
  }

  public void testCancel() {
    SettableFuture<String> f = SettableFuture.create();
    FutureCallback<String> callback =

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/UninterruptibleFutureTest.java
54 issues
Avoid throwing raw exception types.
Design

Line: 104

                    fail("expected to be interrupted");
    } catch (InterruptedException expected) {
    } catch (TimeoutException e) {
      throw new RuntimeException(e);
    }

    // we were interrupted, but it's been cleared now
    assertFalse(Thread.interrupted());


            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 114

                  try {
      assertTrue(delayedFuture.get());
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
    assertTrue(sleeper.completed);
  }



            

Reported by PMD.

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

Line: 43

               * @author Kevin Bourrillion
 * @author Chris Povirk
 */
public class UninterruptibleFutureTest extends TestCase {
  private SleepingRunnable sleeper;
  private Future<Boolean> delayedFuture;

  private final TearDownStack tearDownStack = new TearDownStack();


            

Reported by PMD.

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

Line: 44

               * @author Chris Povirk
 */
public class UninterruptibleFutureTest extends TestCase {
  private SleepingRunnable sleeper;
  private Future<Boolean> delayedFuture;

  private final TearDownStack tearDownStack = new TearDownStack();

  @Override

            

Reported by PMD.

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

Line: 45

               */
public class UninterruptibleFutureTest extends TestCase {
  private SleepingRunnable sleeper;
  private Future<Boolean> delayedFuture;

  private final TearDownStack tearDownStack = new TearDownStack();

  @Override
  protected void setUp() {

            

Reported by PMD.

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

Line: 47

                private SleepingRunnable sleeper;
  private Future<Boolean> delayedFuture;

  private final TearDownStack tearDownStack = new TearDownStack();

  @Override
  protected void setUp() {
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    tearDownStack.addTearDown(

            

Reported by PMD.

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

Line: 49

              
  private final TearDownStack tearDownStack = new TearDownStack();

  @Override
  protected void setUp() {
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    tearDownStack.addTearDown(
        new TearDown() {
          @Override

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 54

                  final ExecutorService executor = Executors.newSingleThreadExecutor();
    tearDownStack.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() {
            executor.shutdownNow();
          }
        });
    sleeper = new SleepingRunnable(1000);

            

Reported by PMD.

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

Line: 60

                        }
        });
    sleeper = new SleepingRunnable(1000);
    delayedFuture = executor.submit(sleeper, true);

    tearDownStack.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() {

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 64

              
    tearDownStack.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() {
            Thread.interrupted();
          }
        });
  }

            

Reported by PMD.

android/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java
54 issues
JUnit tests should include assert() or fail()
Design

Line: 38

               */
@GwtCompatible(emulated = true)
public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

            

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

               */
@GwtCompatible(emulated = true)
public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

            

Reported by PMD.

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

Line: 40

              public class FutureCallbackTest extends TestCase {
  public void testSameThreadSuccess() {
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

  public void testExecutorSuccess() {

            

Reported by PMD.

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

Line: 42

                  SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    addCallback(f, callback, directExecutor());
    f.set("foo");
  }

  public void testExecutorSuccess() {
    CountingSameThreadExecutor ex = new CountingSameThreadExecutor();
    SettableFuture<String> f = SettableFuture.create();

            

Reported by PMD.

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

Line: 45

                  f.set("foo");
  }

  public void testExecutorSuccess() {
    CountingSameThreadExecutor ex = new CountingSameThreadExecutor();
    SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");

            

Reported by PMD.

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

Line: 50

                  SettableFuture<String> f = SettableFuture.create();
    MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");
    assertEquals(1, ex.runCount);
  }

  // Error cases
  public void testSameThreadExecutionException() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                  MockCallback callback = new MockCallback("foo");
    Futures.addCallback(f, callback, ex);
    f.set("foo");
    assertEquals(1, ex.runCount);
  }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();

            

Reported by PMD.

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

Line: 55

                }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();
    Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);

            

Reported by PMD.

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

Line: 55

                }

  // Error cases
  public void testSameThreadExecutionException() {
    SettableFuture<String> f = SettableFuture.create();
    Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);

            

Reported by PMD.

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

Line: 60

                  Exception e = new IllegalArgumentException("foo not found");
    MockCallback callback = new MockCallback(e);
    addCallback(f, callback, directExecutor());
    f.setException(e);
  }

  public void testCancel() {
    SettableFuture<String> f = SettableFuture.create();
    FutureCallback<String> callback =

            

Reported by PMD.

guava/src/com/google/common/collect/MinMaxPriorityQueue.java
54 issues
Using multiple unary operators may be a bug, and/or is confusing.
Error

Line: 500

              
  @VisibleForTesting
  static boolean isEvenLevel(int index) {
    int oneBased = ~~(index + 1); // for GWT
    checkState(oneBased > 0, "negative index");
    return (oneBased & EVEN_POWERS_OF_TWO) > (oneBased & ODD_POWERS_OF_TWO);
  }

  /**

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 570

                  }

    /** Bubbles a value from {@code index} up the appropriate heap if required. */
    void bubbleUp(int index, E x) {
      int crossOver = crossOverUp(index, x);

      Heap heap;
      if (crossOver == index) {
        heap = this;

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 588

                   * element ended up at.
     */
    @CanIgnoreReturnValue
    int bubbleUpAlternatingLevels(int index, E x) {
      while (index > 2) {
        int grandParentIndex = getGrandparentIndex(index);
        E e = elementData(grandParentIndex);
        if (ordering.compare(e, x) <= 0) {
          break;

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 721

                   * @return the position of the new hole (where the lowest grandchild moved from, that had no
     *     grandchild to replace it)
     */
    int fillHoleAt(int index) {
      int minGrandchildIndex;
      while ((minGrandchildIndex = findMinGrandChild(index)) > 0) {
        queue[index] = elementData(minGrandchildIndex);
        index = minGrandchildIndex;
      }

            

Reported by PMD.

Avoid reassigning parameters such as 'c'
Design

Line: 869

                   * Advances nextCursor to the index of the first element after {@code c} that is not in {@code
     * skipMe} and returns {@code size()} if there is no such element.
     */
    private void nextNotInSkipMe(int c) {
      if (nextCursor < c) {
        if (skipMe != null) {
          while (c < size() && foundAndRemovedExactReference(skipMe, elementData(c))) {
            c++;
          }

            

Reported by PMD.

Possible God Class (WMC=59, ATFD=7, TCC=9.804%)
Design

Line: 104

              @Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class MinMaxPriorityQueue<E> extends AbstractQueue<E> {

  /**
   * Creates a new min-max priority queue with default settings: natural order, no maximum size, no
   * initial contents, and an initial expected size of 11.
   */

            

Reported by PMD.

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

Line: 104

              @Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class MinMaxPriorityQueue<E> extends AbstractQueue<E> {

  /**
   * Creates a new min-max priority queue with default settings: natural order, no maximum size, no
   * initial contents, and an initial expected size of 11.
   */

            

Reported by PMD.

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

Line: 173

                   */
    private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);

            

Reported by PMD.

Field expectedSize has the same name as a method
Error

Line: 174

                  private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);
    }

            

Reported by PMD.

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

Line: 174

                  private static final int UNSET_EXPECTED_SIZE = -1;

    private final Comparator<B> comparator;
    private int expectedSize = UNSET_EXPECTED_SIZE;
    private int maximumSize = Integer.MAX_VALUE;

    private Builder(Comparator<B> comparator) {
      this.comparator = checkNotNull(comparator);
    }

            

Reported by PMD.