The following issues were found

android/guava/src/com/google/common/collect/NullsLastOrdering.java
3 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 29

              @ElementTypesAreNonnullByDefault
final class NullsLastOrdering<T extends @Nullable Object> extends Ordering<@Nullable T>
    implements Serializable {
  final Ordering<? super T> ordering;

  NullsLastOrdering(Ordering<? super T> ordering) {
    this.ordering = ordering;
  }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 37

              
  @Override
  public int compare(@CheckForNull T left, @CheckForNull T right) {
    if (left == right) {
      return 0;
    }
    if (left == null) {
      return LEFT_IS_GREATER;
    }

            

Reported by PMD.

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

Line: 53

                @SuppressWarnings("nullness") // should be safe, but not sure if we can avoid the warning
  public <S extends @Nullable T> Ordering<S> reverse() {
    // ordering.reverse() might be optimized, so let it do its thing
    return ordering.reverse().nullsFirst();
  }

  @Override
  public <S extends T> Ordering<@Nullable S> nullsFirst() {
    return ordering.<S>nullsFirst();

            

Reported by PMD.

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

Line: 86

              @DoNotMock("Use Optional.of(value) or Optional.absent()")
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public abstract class Optional<T> implements Serializable {
  /**
   * Returns an {@code Optional} instance with no contained reference.
   *
   * <p><b>Comparison to {@code java.util.Optional}:</b> this method is equivalent to Java 8's
   * {@code Optional.empty}.

            

Reported by PMD.

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

Line: 308

                        protected T computeNext() {
            while (iterator.hasNext()) {
              Optional<? extends T> optional = iterator.next();
              if (optional.isPresent()) {
                return optional.get();
              }
            }
            return endOfData();
          }

            

Reported by PMD.

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

Line: 309

                          while (iterator.hasNext()) {
              Optional<? extends T> optional = iterator.next();
              if (optional.isPresent()) {
                return optional.get();
              }
            }
            return endOfData();
          }
        };

            

Reported by PMD.

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

Line: 33

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class Platform {
  /** Returns the platform preferred implementation of a map based on a hash table. */
  static <K extends @Nullable Object, V extends @Nullable Object>
      Map<K, V> newHashMapWithExpectedSize(int expectedSize) {
    return CompactHashMap.createWithExpectedSize(expectedSize);
  }

            

Reported by PMD.

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

Line: 92

                 * ObjectArrays, which is the main caller of this method.)
   */
  static <T extends @Nullable Object> T[] newArray(T[] reference, int length) {
    Class<?> type = reference.getClass().getComponentType();

    // the cast is safe because
    // result.getClass() == reference.getClass().getComponentType()
    @SuppressWarnings("unchecked")
    T[] result = (T[]) Array.newInstance(type, length);

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 111

                 * - https://github.com/jspecify/jdk/commit/71d826792b8c7ef95d492c50a274deab938f2552
   */
  @SuppressWarnings("nullness")
  static <T extends @Nullable Object> T[] copy(Object[] source, int from, int to, T[] arrayOfType) {
    return Arrays.copyOfRange(source, from, to, (Class<? extends T[]>) arrayOfType.getClass());
  }

  /**
   * Configures the given map maker to use weak keys, if possible; does nothing otherwise (i.e., in

            

Reported by PMD.

android/guava/src/com/google/common/hash/LongAddables.java
3 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: 26

               * @author Louis Wasserman
 */
@ElementTypesAreNonnullByDefault
final class LongAddables {
  private static final Supplier<LongAddable> SUPPLIER;

  static {
    Supplier<LongAddable> supplier;
    try {

            

Reported by PMD.

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

Line: 40

                            return new LongAdder();
            }
          };
    } catch (Throwable t) { // we really want to catch *everything*
      supplier =
          new Supplier<LongAddable>() {
            @Override
            public LongAddable get() {
              return new PureJavaLongAddable();

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 56

                  return SUPPLIER.get();
  }

  private static final class PureJavaLongAddable extends AtomicLong implements LongAddable {
    @Override
    public void increment() {
      getAndIncrement();
    }


            

Reported by PMD.

android/guava/src/com/google/common/collect/RegularImmutableList.java
3 issues
Field size has the same name as a method
Error

Line: 39

              
  // The first `size` elements are non-null.
  @VisibleForTesting final transient @Nullable Object[] array;
  private final transient int size;

  RegularImmutableList(@Nullable Object[] array, int size) {
    this.array = array;
    this.size = size;
  }

            

Reported by PMD.

The user-supplied array 'array' is stored directly.
Design

Line: 41

                @VisibleForTesting final transient @Nullable Object[] array;
  private final transient int size;

  RegularImmutableList(@Nullable Object[] array, int size) {
    this.array = array;
    this.size = size;
  }

  @Override

            

Reported by PMD.

Returning 'array' may expose an internal array.
Design

Line: 59

                @Override
  @Nullable
  Object[] internalArray() {
    return array;
  }

  @Override
  int internalArrayStart() {
    return 0;

            

Reported by PMD.

guava-gwt/src-super/com/google/common/base/super/com/google/common/base/ExtraObjectsMethodsForWeb.java
3 issues
This abstract class does not have any abstract methods
Design

Line: 20

              import org.checkerframework.checker.nullness.qual.Nullable;

/** Holder for extra methods of {@code Objects} only in web. */
abstract class ExtraObjectsMethodsForWeb {
  public static boolean equal(@Nullable String a, @Nullable String b) {
    return a == b;
  }
}

            

Reported by PMD.

Use equals() to compare strings instead of '==' or '!='
Error

Line: 22

              /** Holder for extra methods of {@code Objects} only in web. */
abstract class ExtraObjectsMethodsForWeb {
  public static boolean equal(@Nullable String a, @Nullable String b) {
    return a == b;
  }
}

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 22

              /** Holder for extra methods of {@code Objects} only in web. */
abstract class ExtraObjectsMethodsForWeb {
  public static boolean equal(@Nullable String a, @Nullable String b) {
    return a == b;
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/ListMultimapReplaceValuesTester.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: 35

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListMultimapReplaceValuesTester<K, V> extends AbstractListMultimapTester<K, V> {
  @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testReplaceValuesPreservesOrder() {
    @SuppressWarnings("unchecked")
    List<V> values = Arrays.asList(v3(), v1(), v4());

    for (K k : sampleKeys()) {

            

Reported by PMD.

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

Line: 42

              
    for (K k : sampleKeys()) {
      resetContainer();
      multimap().replaceValues(k, values);
      assertGet(k, values);
    }
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'values' (lines '38'-'45').
Error

Line: 38

                @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
  public void testReplaceValuesPreservesOrder() {
    @SuppressWarnings("unchecked")
    List<V> values = Arrays.asList(v3(), v1(), v4());

    for (K k : sampleKeys()) {
      resetContainer();
      multimap().replaceValues(k, values);
      assertGet(k, values);

            

Reported by PMD.

android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
3 issues
Field elementSet has the same name as a method
Error

Line: 41

                static final ImmutableSortedMultiset<Comparable> NATURAL_EMPTY_MULTISET =
      new RegularImmutableSortedMultiset<>(Ordering.natural());

  @VisibleForTesting final transient RegularImmutableSortedSet<E> elementSet;
  private final transient long[] cumulativeCounts;
  private final transient int offset;
  private final transient int length;

  RegularImmutableSortedMultiset(Comparator<? super E> comparator) {

            

Reported by PMD.

The user-supplied array 'cumulativeCounts' is stored directly.
Design

Line: 54

                }

  RegularImmutableSortedMultiset(
      RegularImmutableSortedSet<E> elementSet, long[] cumulativeCounts, int offset, int length) {
    this.elementSet = elementSet;
    this.cumulativeCounts = cumulativeCounts;
    this.offset = offset;
    this.length = length;
  }

            

Reported by PMD.

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

Line: 67

              
  @Override
  Entry<E> getEntry(int index) {
    return Multisets.immutableEntry(elementSet.asList().get(index), getCount(index));
  }

  @Override
  @CheckForNull
  public Entry<E> firstEntry() {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/ListMultimapEqualsTester.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: 34

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListMultimapEqualsTester<K, V> extends AbstractListMultimapTester<K, V> {
  @CollectionSize.Require(SEVERAL)
  public void testOrderingAffectsEqualsComparisons() {
    ListMultimap<K, V> multimap1 =
        getSubjectGenerator()
            .create(
                Helpers.mapEntry(k0(), v0()),

            

Reported by PMD.

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

Line: 37

                @CollectionSize.Require(SEVERAL)
  public void testOrderingAffectsEqualsComparisons() {
    ListMultimap<K, V> multimap1 =
        getSubjectGenerator()
            .create(
                Helpers.mapEntry(k0(), v0()),
                Helpers.mapEntry(k0(), v1()),
                Helpers.mapEntry(k0(), v0()));
    ListMultimap<K, V> multimap2 =

            

Reported by PMD.

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

Line: 43

                              Helpers.mapEntry(k0(), v1()),
                Helpers.mapEntry(k0(), v0()));
    ListMultimap<K, V> multimap2 =
        getSubjectGenerator()
            .create(
                Helpers.mapEntry(k0(), v1()),
                Helpers.mapEntry(k0(), v0()),
                Helpers.mapEntry(k0(), v0()));
    new EqualsTester().addEqualityGroup(multimap1).addEqualityGroup(multimap2).testEquals();

            

Reported by PMD.

android/guava/src/com/google/common/cache/LongAddables.java
3 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: 28

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class LongAddables {
  private static final Supplier<LongAddable> SUPPLIER;

  static {
    Supplier<LongAddable> supplier;
    try {

            

Reported by PMD.

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

Line: 42

                            return new LongAdder();
            }
          };
    } catch (Throwable t) { // we really want to catch *everything*
      supplier =
          new Supplier<LongAddable>() {
            @Override
            public LongAddable get() {
              return new PureJavaLongAddable();

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 58

                  return SUPPLIER.get();
  }

  private static final class PureJavaLongAddable extends AtomicLong implements LongAddable {
    @Override
    public void increment() {
      getAndIncrement();
    }


            

Reported by PMD.