The following issues were found

guava-tests/test/com/google/common/eventbus/PackageSanityTests.java
3 issues
A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 31

              
public class PackageSanityTests extends AbstractPackageSanityTests {

  public PackageSanityTests() throws Exception {
    DummySubscriber dummySubscriber = new DummySubscriber();
    setDefault(Subscriber.class, dummySubscriber.toSubscriber());
    setDefault(Method.class, DummySubscriber.subscriberMethod());
    setDefault(SubscriberExceptionContext.class, dummySubscriber.toContext());
    setDefault(Dispatcher.class, Dispatcher.immediate());

            

Reported by PMD.

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

Line: 41

              
  private static class DummySubscriber {

    private final EventBus eventBus = new EventBus();

    @Subscribe
    public void handle(@Nullable Object anything) {}

    Subscriber toSubscriber() throws Exception {

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 46

                  @Subscribe
    public void handle(@Nullable Object anything) {}

    Subscriber toSubscriber() throws Exception {
      return Subscriber.create(eventBus, this, subscriberMethod());
    }

    SubscriberExceptionContext toContext() {
      return new SubscriberExceptionContext(eventBus, new Object(), this, subscriberMethod());

            

Reported by PMD.

guava-testlib/test/com/google/common/collect/testing/MinimalCollectionTest.java
3 issues
Avoid throwing null pointer exceptions.
Design

Line: 39

                              // TODO: MinimalCollection should perhaps throw
                for (Object element : elements) {
                  if (element == null) {
                    throw new NullPointerException();
                  }
                }
                return MinimalCollection.of(elements);
              }
            })

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 30

               *
 * @author Kevin Bourrillion
 */
public class MinimalCollectionTest extends TestCase {
  public static Test suite() {
    return CollectionTestSuiteBuilder.using(
            new TestStringCollectionGenerator() {
              @Override
              public Collection<String> create(String[] elements) {

            

Reported by PMD.

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

Line: 31

               * @author Kevin Bourrillion
 */
public class MinimalCollectionTest extends TestCase {
  public static Test suite() {
    return CollectionTestSuiteBuilder.using(
            new TestStringCollectionGenerator() {
              @Override
              public Collection<String> create(String[] elements) {
                // TODO: MinimalCollection should perhaps throw

            

Reported by PMD.

guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java
3 issues
Field shutdown has the same name as a method
Error

Line: 98

                private static final class NoOpScheduledExecutorService extends AbstractListeningExecutorService
      implements ListeningScheduledExecutorService {

    private volatile boolean shutdown;

    @Override
    public void shutdown() {
      shutdown = true;
    }

            

Reported by PMD.

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

Line: 98

                private static final class NoOpScheduledExecutorService extends AbstractListeningExecutorService
      implements ListeningScheduledExecutorService {

    private volatile boolean shutdown;

    @Override
    public void shutdown() {
      shutdown = true;
    }

            

Reported by PMD.

Avoid unused imports such as 'com.google.common.util.concurrent.MoreExecutors'
Design

Line: 27

              import com.google.common.util.concurrent.AbstractListeningExecutorService;
import com.google.common.util.concurrent.ListenableScheduledFuture;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Delayed;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

            

Reported by PMD.

guava-tests/test/com/google/common/escape/CharEscaperBuilderTest.java
3 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: 23

              
public class CharEscaperBuilderTest extends TestCase {

  public void testAddEscapes() {
    char[] cs = {'a', 'b', 'c'};
    CharEscaperBuilder builder = new CharEscaperBuilder().addEscapes(cs, "Z");
    Escaper escaper = builder.toEscaper();
    assertEquals("ZZZdef", escaper.escape("abcdef"));
  }

            

Reported by PMD.

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

Line: 27

                  char[] cs = {'a', 'b', 'c'};
    CharEscaperBuilder builder = new CharEscaperBuilder().addEscapes(cs, "Z");
    Escaper escaper = builder.toEscaper();
    assertEquals("ZZZdef", escaper.escape("abcdef"));
  }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                  char[] cs = {'a', 'b', 'c'};
    CharEscaperBuilder builder = new CharEscaperBuilder().addEscapes(cs, "Z");
    Escaper escaper = builder.toEscaper();
    assertEquals("ZZZdef", escaper.escape("abcdef"));
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/escape/testing/EscaperAsserts.java
3 issues
Avoid empty catch blocks
Error

Line: 52

                  try {
      escaper.escape((String) null);
      Assert.fail("exception not thrown when escaping a null string");
    } catch (NullPointerException e) {
      // pass
    }
  }

  /**

            

Reported by PMD.

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

Line: 52

                  try {
      escaper.escape((String) null);
      Assert.fail("exception not thrown when escaping a null string");
    } catch (NullPointerException e) {
      // pass
    }
  }

  /**

            

Reported by PMD.

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

Line: 52

                  try {
      escaper.escape((String) null);
      Assert.fail("exception not thrown when escaping a null string");
    } catch (NullPointerException e) {
      // pass
    }
  }

  /**

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java
3 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: 36

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetRemoveTester<E> extends AbstractSetTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    getSet().remove(e0());
    assertFalse(
        "After remove(present) a set should not contain the removed element.",

            

Reported by PMD.

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

Line: 39

                @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    getSet().remove(e0());
    assertFalse(
        "After remove(present) a set should not contain the removed element.",
        getSet().contains(e0()));
  }
}

            

Reported by PMD.

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

Line: 42

                  getSet().remove(e0());
    assertFalse(
        "After remove(present) a set should not contain the removed element.",
        getSet().contains(e0()));
  }
}

            

Reported by PMD.

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

Line: 39

              
  @Override
  protected Map<String, Collection<Integer>> makeEmptyMap() {
    return ImmutableSetMultimap.<String, Integer>of().asMap();
  }

  @Override
  protected Map<String, Collection<Integer>> makePopulatedMap() {
    Multimap<String, Integer> delegate = HashMultimap.create();

            

Reported by PMD.

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

Line: 39

              
  @Override
  protected Map<String, Collection<Integer>> makeEmptyMap() {
    return ImmutableSetMultimap.<String, Integer>of().asMap();
  }

  @Override
  protected Map<String, Collection<Integer>> makePopulatedMap() {
    Multimap<String, Integer> delegate = HashMultimap.create();

            

Reported by PMD.

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

Line: 46

                protected Map<String, Collection<Integer>> makePopulatedMap() {
    Multimap<String, Integer> delegate = HashMultimap.create();
    populate(delegate);
    return ImmutableSetMultimap.copyOf(delegate).asMap();
  }
}

            

Reported by PMD.

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

Line: 40

                private static final double[] positiveDoubles = new double[ARRAY_SIZE];

  @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
  RoundingMode mode;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      doubleInIntRange[i] = randomDouble(Integer.SIZE - 2);

            

Reported by PMD.

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

Line: 42

                @Param({"DOWN", "UP", "FLOOR", "CEILING", "HALF_EVEN", "HALF_UP", "HALF_DOWN"})
  RoundingMode mode;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      doubleInIntRange[i] = randomDouble(Integer.SIZE - 2);
      doubleInLongRange[i] = randomDouble(Long.SIZE - 2);
      positiveDoubles[i] = randomPositiveDouble();

            

Reported by PMD.

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

Line: 76

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      tmp += DoubleMath.roundToBigInteger(positiveDoubles[j], mode).intValue();
    }
    return tmp;
  }

  @Benchmark

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 38

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListCreationTester<E> extends AbstractListTester<E> {
  @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testCreateWithDuplicates() {
    E[] array = createSamplesArray();
    array[1] = e0();
    collection = getSubjectGenerator().create(array);

            

Reported by PMD.

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

Line: 43

                public void testCreateWithDuplicates() {
    E[] array = createSamplesArray();
    array[1] = e0();
    collection = getSubjectGenerator().create(array);

    expectContents(array);
  }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '41'-'42').
Error

Line: 41

                @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testCreateWithDuplicates() {
    E[] array = createSamplesArray();
    array[1] = e0();
    collection = getSubjectGenerator().create(array);

    expectContents(array);
  }

            

Reported by PMD.

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

Line: 32

              public class TestByteSink extends ByteSink implements TestStreamSupplier {

  private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  private final ImmutableSet<TestOption> options;

  private boolean outputStreamOpened;
  private boolean outputStreamClosed;

  public TestByteSink(TestOption... options) {

            

Reported by PMD.

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

Line: 34

                private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  private final ImmutableSet<TestOption> options;

  private boolean outputStreamOpened;
  private boolean outputStreamClosed;

  public TestByteSink(TestOption... options) {
    this.options = ImmutableSet.copyOf(options);
  }

            

Reported by PMD.

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

Line: 35

                private final ImmutableSet<TestOption> options;

  private boolean outputStreamOpened;
  private boolean outputStreamClosed;

  public TestByteSink(TestOption... options) {
    this.options = ImmutableSet.copyOf(options);
  }


            

Reported by PMD.