The following issues were found

android/guava/src/com/google/common/collect/Serialization.java
9 issues
The String literal 'unchecked' appears 5 times in this file; the first occurrence is on line 86
Error

Line: 86

                    Map<K, V> map, ObjectInputStream stream, int size)
      throws IOException, ClassNotFoundException {
    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked") // reading data stored by writeMap
      K key = (K) stream.readObject();
      @SuppressWarnings("unchecked") // reading data stored by writeMap
      V value = (V) stream.readObject();
      map.put(key, value);
    }

            

Reported by PMD.

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

Line: 103

                 */
  static <E extends @Nullable Object> void writeMultiset(
      Multiset<E> multiset, ObjectOutputStream stream) throws IOException {
    int entryCount = multiset.entrySet().size();
    stream.writeInt(entryCount);
    for (Multiset.Entry<E> entry : multiset.entrySet()) {
      stream.writeObject(entry.getElement());
      stream.writeInt(entry.getCount());
    }

            

Reported by PMD.

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

Line: 147

                 */
  static <K extends @Nullable Object, V extends @Nullable Object> void writeMultimap(
      Multimap<K, V> multimap, ObjectOutputStream stream) throws IOException {
    stream.writeInt(multimap.asMap().size());
    for (Map.Entry<K, Collection<V>> entry : multimap.asMap().entrySet()) {
      stream.writeObject(entry.getKey());
      stream.writeInt(entry.getValue().size());
      for (V value : entry.getValue()) {
        stream.writeObject(value);

            

Reported by PMD.

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

Line: 148

                static <K extends @Nullable Object, V extends @Nullable Object> void writeMultimap(
      Multimap<K, V> multimap, ObjectOutputStream stream) throws IOException {
    stream.writeInt(multimap.asMap().size());
    for (Map.Entry<K, Collection<V>> entry : multimap.asMap().entrySet()) {
      stream.writeObject(entry.getKey());
      stream.writeInt(entry.getValue().size());
      for (V value : entry.getValue()) {
        stream.writeObject(value);
      }

            

Reported by PMD.

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

Line: 150

                  stream.writeInt(multimap.asMap().size());
    for (Map.Entry<K, Collection<V>> entry : multimap.asMap().entrySet()) {
      stream.writeObject(entry.getKey());
      stream.writeInt(entry.getValue().size());
      for (V value : entry.getValue()) {
        stream.writeObject(value);
      }
    }
  }

            

Reported by PMD.

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

Line: 184

                    for (int j = 0; j < valueCount; j++) {
        @SuppressWarnings("unchecked") // reading data stored by writeMultimap
        V value = (V) stream.readObject();
        values.add(value);
      }
    }
  }

  // Secret sauce for setting final fields; don't make it public.

            

Reported by PMD.

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

Line: 201

              
  // Secret sauce for setting final fields; don't make it public.
  static final class FieldSetter<T> {
    private final Field field;

    private FieldSetter(Field field) {
      this.field = field;
      field.setAccessible(true);
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'values' (lines '179'-'187').
Error

Line: 179

                  for (int i = 0; i < distinctKeys; i++) {
      @SuppressWarnings("unchecked") // reading data stored by writeMultimap
      K key = (K) stream.readObject();
      Collection<V> values = multimap.get(key);
      int valueCount = stream.readInt();
      for (int j = 0; j < valueCount; j++) {
        @SuppressWarnings("unchecked") // reading data stored by writeMultimap
        V value = (V) stream.readObject();
        values.add(value);

            

Reported by PMD.

Found 'DD'-anomaly for variable 'values' (lines '179'-'179').
Error

Line: 179

                  for (int i = 0; i < distinctKeys; i++) {
      @SuppressWarnings("unchecked") // reading data stored by writeMultimap
      K key = (K) stream.readObject();
      Collection<V> values = multimap.get(key);
      int valueCount = stream.readInt();
      for (int j = 0; j < valueCount; j++) {
        @SuppressWarnings("unchecked") // reading data stored by writeMultimap
        V value = (V) stream.readObject();
        values.add(value);

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

               */
@GwtCompatible
public final class OneSizeGenerator<T, E> implements OneSizeTestContainerGenerator<T, E> {
  private final TestContainerGenerator<T, E> generator;
  private final CollectionSize collectionSize;

  public OneSizeGenerator(TestContainerGenerator<T, E> generator, CollectionSize collectionSize) {
    this.generator = generator;
    this.collectionSize = collectionSize;

            

Reported by PMD.

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

Line: 63

              
  @Override
  public T createTestSubject() {
    Collection<E> elements = getSampleElements(getCollectionSize().getNumElements());
    return generator.create(elements.toArray());
  }

  @Override
  public Collection<E> getSampleElements(int howMany) {

            

Reported by PMD.

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

Line: 64

                @Override
  public T createTestSubject() {
    Collection<E> elements = getSampleElements(getCollectionSize().getNumElements());
    return generator.create(elements.toArray());
  }

  @Override
  public Collection<E> getSampleElements(int howMany) {
    SampleElements<E> samples = samples();

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 72

                  SampleElements<E> samples = samples();
    @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {

            

Reported by PMD.

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

Line: 73

                  @SuppressWarnings("unchecked")
    List<E> allSampleElements =
        Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    return new ArrayList<E>(allSampleElements.subList(0, howMany));
  }

  @Override
  public CollectionSize getCollectionSize() {
    return collectionSize;

            

Reported by PMD.

android/guava/src/com/google/common/collect/EnumBiMap.java
9 issues
Field keyType has the same name as a method
Error

Line: 43

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class EnumBiMap<K extends Enum<K>, V extends Enum<V>> extends AbstractBiMap<K, V> {
  private transient Class<K> keyType;
  private transient Class<V> valueType;

  /**
   * Returns a new, empty {@code EnumBiMap} using the specified key and value types.
   *

            

Reported by PMD.

Field valueType has the same name as a method
Error

Line: 44

              @ElementTypesAreNonnullByDefault
public final class EnumBiMap<K extends Enum<K>, V extends Enum<V>> extends AbstractBiMap<K, V> {
  private transient Class<K> keyType;
  private transient Class<V> valueType;

  /**
   * Returns a new, empty {@code EnumBiMap} using the specified key and value types.
   *
   * @param keyType the key type

            

Reported by PMD.

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

Line: 68

                 */
  public static <K extends Enum<K>, V extends Enum<V>> EnumBiMap<K, V> create(Map<K, V> map) {
    EnumBiMap<K, V> bimap = create(inferKeyType(map), inferValueType(map));
    bimap.putAll(map);
    return bimap;
  }

  private EnumBiMap(Class<K> keyType, Class<V> valueType) {
    super(new EnumMap<K, V>(keyType), new EnumMap<V, K>(valueType));

            

Reported by PMD.

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

Line: 86

                    return ((EnumHashBiMap<K, ?>) map).keyType();
    }
    checkArgument(!map.isEmpty());
    return map.keySet().iterator().next().getDeclaringClass();
  }

  private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
    if (map instanceof EnumBiMap) {
      return ((EnumBiMap<?, V>) map).valueType;

            

Reported by PMD.

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

Line: 86

                    return ((EnumHashBiMap<K, ?>) map).keyType();
    }
    checkArgument(!map.isEmpty());
    return map.keySet().iterator().next().getDeclaringClass();
  }

  private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
    if (map instanceof EnumBiMap) {
      return ((EnumBiMap<?, V>) map).valueType;

            

Reported by PMD.

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

Line: 86

                    return ((EnumHashBiMap<K, ?>) map).keyType();
    }
    checkArgument(!map.isEmpty());
    return map.keySet().iterator().next().getDeclaringClass();
  }

  private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
    if (map instanceof EnumBiMap) {
      return ((EnumBiMap<?, V>) map).valueType;

            

Reported by PMD.

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

Line: 94

                    return ((EnumBiMap<?, V>) map).valueType;
    }
    checkArgument(!map.isEmpty());
    return map.values().iterator().next().getDeclaringClass();
  }

  /** Returns the associated key type. */
  public Class<K> keyType() {
    return keyType;

            

Reported by PMD.

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

Line: 94

                    return ((EnumBiMap<?, V>) map).valueType;
    }
    checkArgument(!map.isEmpty());
    return map.values().iterator().next().getDeclaringClass();
  }

  /** Returns the associated key type. */
  public Class<K> keyType() {
    return keyType;

            

Reported by PMD.

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

Line: 94

                    return ((EnumBiMap<?, V>) map).valueType;
    }
    checkArgument(!map.isEmpty());
    return map.values().iterator().next().getDeclaringClass();
  }

  /** Returns the associated key type. */
  public Class<K> keyType() {
    return keyType;

            

Reported by PMD.

android/guava/src/com/google/common/hash/LittleEndianByteArray.java
9 issues
Avoid throwing raw exception types.
Design

Line: 191

                            }
            });
      } catch (java.security.PrivilegedActionException e) {
        throw new RuntimeException("Could not initialize intrinsics", e.getCause());
      }
    }

    static {
      theUnsafe = getUnsafe();

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 170

                   */
    private static sun.misc.Unsafe getUnsafe() {
      try {
        return sun.misc.Unsafe.getUnsafe();
      } catch (SecurityException tryReflectionInstead) {
        // We'll try reflection instead.
      }
      try {
        return java.security.AccessController.doPrivileged(

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 171

                  private static sun.misc.Unsafe getUnsafe() {
      try {
        return sun.misc.Unsafe.getUnsafe();
      } catch (SecurityException tryReflectionInstead) {
        // We'll try reflection instead.
      }
      try {
        return java.security.AccessController.doPrivileged(
            new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {

            

Reported by PMD.

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

Line: 191

                            }
            });
      } catch (java.security.PrivilegedActionException e) {
        throw new RuntimeException("Could not initialize intrinsics", e.getCause());
      }
    }

    static {
      theUnsafe = getUnsafe();

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 200

                    BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);

      // sanity check - this should never fail
      if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
        throw new AssertionError();
      }
    }
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 253

                              ? UnsafeByteArray.UNSAFE_LITTLE_ENDIAN
                : UnsafeByteArray.UNSAFE_BIG_ENDIAN;
      }
    } catch (Throwable t) {
      // ensure we really catch *everything*
    }
    byteArray = theGetter;
  }


            

Reported by PMD.

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

Line: 253

                              ? UnsafeByteArray.UNSAFE_LITTLE_ENDIAN
                : UnsafeByteArray.UNSAFE_BIG_ENDIAN;
      }
    } catch (Throwable t) {
      // ensure we really catch *everything*
    }
    byteArray = theGetter;
  }


            

Reported by PMD.

Avoid importing anything from the sun.* packages
Error

Line: 19

              
import com.google.common.primitives.Longs;
import java.nio.ByteOrder;
import sun.misc.Unsafe;

/**
 * Utility functions for loading and storing values from a byte array.
 *
 * @author Kevin Damm

            

Reported by PMD.

Found 'DU'-anomaly for variable 'mask' (lines '224'-'228').
Error

Line: 224

              
      @Override
      public void putLongLittleEndian(byte[] sink, int offset, long value) {
        long mask = 0xFFL;
        for (int i = 0; i < 8; mask <<= 8, i++) {
          sink[offset + i] = (byte) ((value & mask) >> (i * 8));
        }
      }
    };

            

Reported by PMD.

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

Line: 64

                /** A byte source that reads from a URL using {@link URL#openStream()}. */
  private static final class UrlByteSource extends ByteSource {

    private final URL url;

    private UrlByteSource(URL url) {
      this.url = checkNotNull(url);
    }


            

Reported by PMD.

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

Line: 87

                 * @since 14.0
   */
  public static CharSource asCharSource(URL url, Charset charset) {
    return asByteSource(url).asCharSource(charset);
  }

  /**
   * Reads all bytes from a URL into a byte array.
   *

            

Reported by PMD.

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

Line: 98

                 * @throws IOException if an I/O error occurs
   */
  public static byte[] toByteArray(URL url) throws IOException {
    return asByteSource(url).read();
  }

  /**
   * Reads all characters from a URL into a {@link String}, using the given character set.
   *

            

Reported by PMD.

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

Line: 111

                 * @throws IOException if an I/O error occurs.
   */
  public static String toString(URL url, Charset charset) throws IOException {
    return asCharSource(url, charset).read();
  }

  /**
   * Streams lines from a URL, stopping when our callback returns false, or we have read all of the
   * lines.

            

Reported by PMD.

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

Line: 129

                @ParametricNullness
  public static <T extends @Nullable Object> T readLines(
      URL url, Charset charset, LineProcessor<T> callback) throws IOException {
    return asCharSource(url, charset).readLines(callback);
  }

  /**
   * Reads all of the lines from a URL. The lines do not include line-termination characters, but do
   * include other leading and trailing whitespace.

            

Reported by PMD.

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

Line: 175

                 * @throws IOException if an I/O error occurs
   */
  public static void copy(URL from, OutputStream to) throws IOException {
    asByteSource(from).copyTo(to);
  }

  /**
   * Returns a {@code URL} pointing to {@code resourceName} if the resource is found using the
   * {@linkplain Thread#getContextClassLoader() context class loader}. In simple environments, the

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 196

                public static URL getResource(String resourceName) {
    ClassLoader loader =
        MoreObjects.firstNonNull(
            Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader());
    URL url = loader.getResource(resourceName);
    checkArgument(url != null, "resource %s not found.", resourceName);
    return url;
  }


            

Reported by PMD.

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

Line: 196

                public static URL getResource(String resourceName) {
    ClassLoader loader =
        MoreObjects.firstNonNull(
            Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader());
    URL url = loader.getResource(resourceName);
    checkArgument(url != null, "resource %s not found.", resourceName);
    return url;
  }


            

Reported by PMD.

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

Line: 197

                  ClassLoader loader =
        MoreObjects.firstNonNull(
            Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader());
    URL url = loader.getResource(resourceName);
    checkArgument(url != null, "resource %s not found.", resourceName);
    return url;
  }

  /**

            

Reported by PMD.

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

Line: 131

                }

  private final class PreOrderIterator extends UnmodifiableIterator<T> {
    private final Deque<Iterator<T>> stack;

    PreOrderIterator(T root) {
      this.stack = new ArrayDeque<>();
      stack.addLast(Iterators.singletonIterator(checkNotNull(root)));
    }

            

Reported by PMD.

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

Line: 150

                    if (!itr.hasNext()) {
        stack.removeLast();
      }
      Iterator<T> childItr = children(result).iterator();
      if (childItr.hasNext()) {
        stack.addLast(childItr);
      }
      return result;
    }

            

Reported by PMD.

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

Line: 184

                }

  private static final class PostOrderNode<T> {
    final T root;
    final Iterator<T> childIterator;

    PostOrderNode(T root, Iterator<T> childIterator) {
      this.root = checkNotNull(root);
      this.childIterator = checkNotNull(childIterator);

            

Reported by PMD.

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

Line: 185

              
  private static final class PostOrderNode<T> {
    final T root;
    final Iterator<T> childIterator;

    PostOrderNode(T root, Iterator<T> childIterator) {
      this.root = checkNotNull(root);
      this.childIterator = checkNotNull(childIterator);
    }

            

Reported by PMD.

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

Line: 194

                }

  private final class PostOrderIterator extends AbstractIterator<T> {
    private final ArrayDeque<PostOrderNode<T>> stack;

    PostOrderIterator(T root) {
      this.stack = new ArrayDeque<>();
      stack.addLast(expand(root));
    }

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 206

                  protected T computeNext() {
      while (!stack.isEmpty()) {
        PostOrderNode<T> top = stack.getLast();
        if (top.childIterator.hasNext()) {
          T child = top.childIterator.next();
          stack.addLast(expand(child));
        } else {
          stack.removeLast();
          return top.root;

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 207

                    while (!stack.isEmpty()) {
        PostOrderNode<T> top = stack.getLast();
        if (top.childIterator.hasNext()) {
          T child = top.childIterator.next();
          stack.addLast(expand(child));
        } else {
          stack.removeLast();
          return top.root;
        }

            

Reported by PMD.

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

Line: 218

                  }

    private PostOrderNode<T> expand(T t) {
      return new PostOrderNode<T>(t, children(t).iterator());
    }
  }

  /**
   * Returns an unmodifiable iterable over the nodes in a tree structure, using breadth-first

            

Reported by PMD.

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

Line: 245

              
  private final class BreadthFirstIterator extends UnmodifiableIterator<T>
      implements PeekingIterator<T> {
    private final Queue<T> queue;

    BreadthFirstIterator(T root) {
      this.queue = new ArrayDeque<T>();
      queue.add(root);
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/reflect/TypeVisitorTest.java
9 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

               */
public class TypeVisitorTest extends TestCase {

  public void testVisitNull() {
    new BaseTypeVisitor()
        .visit(((ParameterizedType) ArrayList.class.getGenericSuperclass()).getOwnerType());
  }

  public void testVisitClass() {

            

Reported by PMD.

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

Line: 35

               */
public class TypeVisitorTest extends TestCase {

  public void testVisitNull() {
    new BaseTypeVisitor()
        .visit(((ParameterizedType) ArrayList.class.getGenericSuperclass()).getOwnerType());
  }

  public void testVisitClass() {

            

Reported by PMD.

Avoid using implementation types like 'ArrayList'; use the interface instead
Design

Line: 37

              
  public void testVisitNull() {
    new BaseTypeVisitor()
        .visit(((ParameterizedType) ArrayList.class.getGenericSuperclass()).getOwnerType());
  }

  public void testVisitClass() {
    assertVisited(String.class);
    new BaseTypeVisitor() {

            

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

                      .visit(((ParameterizedType) ArrayList.class.getGenericSuperclass()).getOwnerType());
  }

  public void testVisitClass() {
    assertVisited(String.class);
    new BaseTypeVisitor() {
      @Override
      void visitClass(Class<?> t) {}
    }.visit(String.class);

            

Reported by PMD.

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

Line: 48

                  }.visit(String.class);
  }

  public <T> void testVisitTypeVariable() {
    Type type = new TypeCapture<T>() {}.capture();
    assertVisited(type);
    new BaseTypeVisitor() {
      @Override
      void visitTypeVariable(TypeVariable<?> t) {}

            

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

                  }.visit(type);
  }

  public void testVisitWildcardType() {
    WildcardType type = Types.subtypeOf(String.class);
    assertVisited(type);
    new BaseTypeVisitor() {
      @Override
      void visitWildcardType(WildcardType t) {}

            

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

                  }.visit(type);
  }

  public <T> void testVisitGenericArrayType() {
    Type type = new TypeCapture<T[]>() {}.capture();
    assertVisited(type);
    new BaseTypeVisitor() {
      @Override
      void visitGenericArrayType(GenericArrayType t) {}

            

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

                  }.visit(type);
  }

  public <T> void testVisitParameterizedType() {
    Type type = new TypeCapture<Iterable<T>>() {}.capture();
    assertVisited(type);
    new BaseTypeVisitor() {
      @Override
      void visitParameterizedType(ParameterizedType t) {}

            

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

                  }.visit(type);
  }

  public <E extends Enum<E>> void testVisitRecursiveTypeBounds() {
    Type type = new TypeCapture<EnumSet<E>>() {}.capture();
    assertVisited(type);
    new BaseTypeVisitor() {
      @Override
      void visitParameterizedType(ParameterizedType t) {

            

Reported by PMD.

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

Line: 39

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class AbstractSortedMultiset<E extends @Nullable Object> extends AbstractMultiset<E>
    implements SortedMultiset<E> {
  @GwtTransient final Comparator<? super E> comparator;

  // needed for serialization
  @SuppressWarnings("unchecked")
  AbstractSortedMultiset() {

            

Reported by PMD.

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

Line: 40

              @ElementTypesAreNonnullByDefault
abstract class AbstractSortedMultiset<E extends @Nullable Object> extends AbstractMultiset<E>
    implements SortedMultiset<E> {
  @GwtTransient final Comparator<? super E> comparator;

  // needed for serialization
  @SuppressWarnings("unchecked")
  AbstractSortedMultiset() {
    this((Comparator) Ordering.natural());

            

Reported by PMD.

Field comparator has the same name as a method
Error

Line: 40

              @ElementTypesAreNonnullByDefault
abstract class AbstractSortedMultiset<E extends @Nullable Object> extends AbstractMultiset<E>
    implements SortedMultiset<E> {
  @GwtTransient final Comparator<? super E> comparator;

  // needed for serialization
  @SuppressWarnings("unchecked")
  AbstractSortedMultiset() {
    this((Comparator) Ordering.natural());

            

Reported by PMD.

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

Line: 87

                  Iterator<Entry<E>> entryIterator = entryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
      entryIterator.remove();
      return result;
    }
    return null;
  }

            

Reported by PMD.

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

Line: 87

                  Iterator<Entry<E>> entryIterator = entryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
      entryIterator.remove();
      return result;
    }
    return null;
  }

            

Reported by PMD.

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

Line: 100

                  Iterator<Entry<E>> entryIterator = descendingEntryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
      entryIterator.remove();
      return result;
    }
    return null;
  }

            

Reported by PMD.

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

Line: 100

                  Iterator<Entry<E>> entryIterator = descendingEntryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
      entryIterator.remove();
      return result;
    }
    return null;
  }

            

Reported by PMD.

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

Line: 116

                  // These are checked elsewhere, but NullPointerTester wants them checked eagerly.
    checkNotNull(fromBoundType);
    checkNotNull(toBoundType);
    return tailMultiset(fromElement, fromBoundType).headMultiset(toElement, toBoundType);
  }

  abstract Iterator<Entry<E>> descendingEntryIterator();

  Iterator<E> descendingIterator() {

            

Reported by PMD.

Field descendingMultiset has the same name as a method
Error

Line: 125

                  return Multisets.iteratorImpl(descendingMultiset());
  }

  @CheckForNull private transient SortedMultiset<E> descendingMultiset;

  @Override
  public SortedMultiset<E> descendingMultiset() {
    SortedMultiset<E> result = descendingMultiset;
    return (result == null) ? descendingMultiset = createDescendingMultiset() : result;

            

Reported by PMD.

android/guava/src/com/google/common/base/Ascii.java
9 issues
Avoid reassigning parameters such as 'seq'
Design

Line: 550

                 *     truncationIndicator}
   * @since 16.0
   */
  public static String truncate(CharSequence seq, int maxLength, String truncationIndicator) {
    checkNotNull(seq);

    // length to truncate the sequence to, not including the truncation indicator
    int truncationLength = maxLength - truncationIndicator.length();


            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 622

                    if (alphaIndex < 26 && alphaIndex == getAlphaIndex(c2)) {
        continue;
      }
      return false;
    }
    return true;
  }

  /**

            

Reported by PMD.

Avoid reassigning the loop control variable 'i'
Design

Line: 412

                  for (int i = 0; i < length; i++) {
      if (isUpperCase(string.charAt(i))) {
        char[] chars = string.toCharArray();
        for (; i < length; i++) {
          char c = chars[i];
          if (isUpperCase(c)) {
            chars[i] = (char) (c ^ CASE_MASK);
          }
        }

            

Reported by PMD.

Avoid modifying an outer loop incrementer in an inner loop for update expression
Error

Line: 412

                  for (int i = 0; i < length; i++) {
      if (isUpperCase(string.charAt(i))) {
        char[] chars = string.toCharArray();
        for (; i < length; i++) {
          char c = chars[i];
          if (isUpperCase(c)) {
            chars[i] = (char) (c ^ CASE_MASK);
          }
        }

            

Reported by PMD.

Avoid reassigning the loop control variable 'i'
Design

Line: 460

                  for (int i = 0; i < length; i++) {
      if (isLowerCase(string.charAt(i))) {
        char[] chars = string.toCharArray();
        for (; i < length; i++) {
          char c = chars[i];
          if (isLowerCase(c)) {
            chars[i] = (char) (c ^ CASE_MASK);
          }
        }

            

Reported by PMD.

Avoid modifying an outer loop incrementer in an inner loop for update expression
Error

Line: 460

                  for (int i = 0; i < length; i++) {
      if (isLowerCase(string.charAt(i))) {
        char[] chars = string.toCharArray();
        for (; i < length; i++) {
          char c = chars[i];
          if (isLowerCase(c)) {
            chars[i] = (char) (c ^ CASE_MASK);
          }
        }

            

Reported by PMD.

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

Line: 566

              
    if (seq.length() <= maxLength) {
      String string = seq.toString();
      if (string.length() <= maxLength) {
        return string;
      }
      // if the length of the toString() result was > maxLength for some reason, truncate that
      seq = string;
    }

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 604

                public static boolean equalsIgnoreCase(CharSequence s1, CharSequence s2) {
    // Calling length() is the null pointer check (so do it before we can exit early).
    int length = s1.length();
    if (s1 == s2) {
      return true;
    }
    if (length != s2.length()) {
      return false;
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'length' (lines '603'-'625').
Error

Line: 603

                 */
  public static boolean equalsIgnoreCase(CharSequence s1, CharSequence s2) {
    // Calling length() is the null pointer check (so do it before we can exit early).
    int length = s1.length();
    if (s1 == s2) {
      return true;
    }
    if (length != s2.length()) {
      return false;

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/BiMapInverseTester.java
9 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: 45

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

  public void testInverseSame() {
    assertSame(getMap(), getMap().inverse().inverse());
  }

  @CollectionFeature.Require(SERIALIZABLE)
  public void testInverseSerialization() {

            

Reported by PMD.

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

Line: 46

              public class BiMapInverseTester<K, V> extends AbstractBiMapTester<K, V> {

  public void testInverseSame() {
    assertSame(getMap(), getMap().inverse().inverse());
  }

  @CollectionFeature.Require(SERIALIZABLE)
  public void testInverseSerialization() {
    BiMapPair<K, V> pair = new BiMapPair<>(getMap());

            

Reported by PMD.

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

Line: 46

              public class BiMapInverseTester<K, V> extends AbstractBiMapTester<K, V> {

  public void testInverseSame() {
    assertSame(getMap(), getMap().inverse().inverse());
  }

  @CollectionFeature.Require(SERIALIZABLE)
  public void testInverseSerialization() {
    BiMapPair<K, V> pair = new BiMapPair<>(getMap());

            

Reported by PMD.

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

Line: 49

                  assertSame(getMap(), getMap().inverse().inverse());
  }

  @CollectionFeature.Require(SERIALIZABLE)
  public void testInverseSerialization() {
    BiMapPair<K, V> pair = new BiMapPair<>(getMap());
    BiMapPair<K, V> copy = SerializableTester.reserialize(pair);
    assertEquals(pair.forward, copy.forward);
    assertEquals(pair.backward, copy.backward);

            

Reported by PMD.

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

Line: 50

                }

  @CollectionFeature.Require(SERIALIZABLE)
  public void testInverseSerialization() {
    BiMapPair<K, V> pair = new BiMapPair<>(getMap());
    BiMapPair<K, V> copy = SerializableTester.reserialize(pair);
    assertEquals(pair.forward, copy.forward);
    assertEquals(pair.backward, copy.backward);
    assertSame(copy.backward, copy.forward.inverse());

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 55

                  BiMapPair<K, V> copy = SerializableTester.reserialize(pair);
    assertEquals(pair.forward, copy.forward);
    assertEquals(pair.backward, copy.backward);
    assertSame(copy.backward, copy.forward.inverse());
    assertSame(copy.forward, copy.backward.inverse());
  }

  private static class BiMapPair<K, V> implements Serializable {
    final BiMap<K, V> forward;

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 56

                  assertEquals(pair.forward, copy.forward);
    assertEquals(pair.backward, copy.backward);
    assertSame(copy.backward, copy.forward.inverse());
    assertSame(copy.forward, copy.backward.inverse());
  }

  private static class BiMapPair<K, V> implements Serializable {
    final BiMap<K, V> forward;
    final BiMap<V, K> backward;

            

Reported by PMD.

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

Line: 60

                }

  private static class BiMapPair<K, V> implements Serializable {
    final BiMap<K, V> forward;
    final BiMap<V, K> backward;

    BiMapPair(BiMap<K, V> original) {
      this.forward = original;
      this.backward = original.inverse();

            

Reported by PMD.

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

Line: 61

              
  private static class BiMapPair<K, V> implements Serializable {
    final BiMap<K, V> forward;
    final BiMap<V, K> backward;

    BiMapPair(BiMap<K, V> original) {
      this.forward = original;
      this.backward = original.inverse();
    }

            

Reported by PMD.