The following issues were found

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.

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

Line: 40

                    new RegularImmutableSet<>(EMPTY_ARRAY, 0, EMPTY_ARRAY, 0);

  private final transient Object[] elements;
  private final transient int hashCode;
  // the same values as `elements` in hashed positions (plus nulls)
  @VisibleForTesting final transient @Nullable Object[] table;
  // 'and' with an int to get a valid table index.
  private final transient int mask;


            

Reported by PMD.

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

Line: 46

                // 'and' with an int to get a valid table index.
  private final transient int mask;

  RegularImmutableSet(Object[] elements, int hashCode, @Nullable Object[] table, int mask) {
    this.elements = elements;
    this.hashCode = hashCode;
    this.table = table;
    this.mask = mask;
  }

            

Reported by PMD.

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

Line: 46

                // 'and' with an int to get a valid table index.
  private final transient int mask;

  RegularImmutableSet(Object[] elements, int hashCode, @Nullable Object[] table, int mask) {
    this.elements = elements;
    this.hashCode = hashCode;
    this.table = table;
    this.mask = mask;
  }

            

Reported by PMD.

Avoid reassigning the loop control variable 'i'
Design

Line: 60

                    return false;
    }
    for (int i = Hashing.smearedHash(target); ; i++) {
      i &= mask;
      Object candidate = table[i];
      if (candidate == null) {
        return false;
      } else if (candidate.equals(target)) {
        return true;

            

Reported by PMD.

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

Line: 64

                    Object candidate = table[i];
      if (candidate == null) {
        return false;
      } else if (candidate.equals(target)) {
        return true;
      }
    }
  }


            

Reported by PMD.

Returning 'elements' may expose an internal array.
Design

Line: 87

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

  @Override
  int internalArrayStart() {
    return 0;

            

Reported by PMD.

Ensure you override both equals() and hashCode()
Error

Line: 119

                }

  @Override
  public int hashCode() {
    return hashCode;
  }

  @Override
  boolean isHashCodeFast() {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'i' (lines '59'-'59').
Error

Line: 59

                  if (target == null || table.length == 0) {
      return false;
    }
    for (int i = Hashing.smearedHash(target); ; i++) {
      i &= mask;
      Object candidate = table[i];
      if (candidate == null) {
        return false;
      } else if (candidate.equals(target)) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'i' (lines '59'-'68').
Error

Line: 59

                  if (target == null || table.length == 0) {
      return false;
    }
    for (int i = Hashing.smearedHash(target); ; i++) {
      i &= mask;
      Object candidate = table[i];
      if (candidate == null) {
        return false;
      } else if (candidate.equals(target)) {

            

Reported by PMD.

guava/src/com/google/common/collect/IndexedImmutableSet.java
9 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 29

              
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
abstract class IndexedImmutableSet<E> extends ImmutableSet<E> {
  abstract E get(int index);

  @Override
  public UnmodifiableIterator<E> iterator() {
    return asList().iterator();

            

Reported by PMD.

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

Line: 34

              
  @Override
  public UnmodifiableIterator<E> iterator() {
    return asList().iterator();
  }

  @Override
  public Spliterator<E> spliterator() {
    return CollectSpliterators.indexed(size(), SPLITERATOR_CHARACTERISTICS, this::get);

            

Reported by PMD.

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

Line: 54

                @Override
  @GwtIncompatible
  int copyIntoArray(@Nullable Object[] dst, int offset) {
    return asList().copyIntoArray(dst, offset);
  }

  @Override
  ImmutableList<E> createAsList() {
    return new ImmutableAsList<E>() {

            

Reported by PMD.

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

Line: 62

                  return new ImmutableAsList<E>() {
      @Override
      public E get(int index) {
        return IndexedImmutableSet.this.get(index);
      }

      @Override
      boolean isPartialView() {
        return IndexedImmutableSet.this.isPartialView();

            

Reported by PMD.

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

Line: 62

                  return new ImmutableAsList<E>() {
      @Override
      public E get(int index) {
        return IndexedImmutableSet.this.get(index);
      }

      @Override
      boolean isPartialView() {
        return IndexedImmutableSet.this.isPartialView();

            

Reported by PMD.

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

Line: 67

              
      @Override
      boolean isPartialView() {
        return IndexedImmutableSet.this.isPartialView();
      }

      @Override
      public int size() {
        return IndexedImmutableSet.this.size();

            

Reported by PMD.

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

Line: 67

              
      @Override
      boolean isPartialView() {
        return IndexedImmutableSet.this.isPartialView();
      }

      @Override
      public int size() {
        return IndexedImmutableSet.this.size();

            

Reported by PMD.

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

Line: 72

              
      @Override
      public int size() {
        return IndexedImmutableSet.this.size();
      }

      @Override
      ImmutableCollection<E> delegateCollection() {
        return IndexedImmutableSet.this;

            

Reported by PMD.

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

Line: 72

              
      @Override
      public int size() {
        return IndexedImmutableSet.this.size();
      }

      @Override
      ImmutableCollection<E> delegateCollection() {
        return IndexedImmutableSet.this;

            

Reported by PMD.

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/src/com/google/common/base/SmallCharMatcher.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 32

              @ElementTypesAreNonnullByDefault
final class SmallCharMatcher extends NamedFastMatcher {
  static final int MAX_SIZE = 1023;
  private final char[] table;
  private final boolean containsZero;
  private final long filter;

  private SmallCharMatcher(char[] table, long filter, boolean containsZero, String description) {
    super(description);

            

Reported by PMD.

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

Line: 33

              final class SmallCharMatcher extends NamedFastMatcher {
  static final int MAX_SIZE = 1023;
  private final char[] table;
  private final boolean containsZero;
  private final long filter;

  private SmallCharMatcher(char[] table, long filter, boolean containsZero, String description) {
    super(description);
    this.table = table;

            

Reported by PMD.

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

Line: 34

                static final int MAX_SIZE = 1023;
  private final char[] table;
  private final boolean containsZero;
  private final long filter;

  private SmallCharMatcher(char[] table, long filter, boolean containsZero, String description) {
    super(description);
    this.table = table;
    this.filter = filter;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 75

                 */
  @VisibleForTesting
  static int chooseTableSize(int setSize) {
    if (setSize == 1) {
      return 2;
    }
    // Correct the size for open addressing to match desired load factor.
    // Round up to the next highest power of 2.
    int tableSize = Integer.highestOneBit(setSize - 1) << 1;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'mask' (lines '94'-'110').
Error

Line: 94

                  boolean containsZero = chars.get(0);
    // Compute the hash table.
    char[] table = new char[chooseTableSize(size)];
    int mask = table.length - 1;
    for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
      // Compute the filter at the same time.
      filter |= 1L << c;
      int index = smear(c) & mask;
      while (true) {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'index' (lines '98'-'98').
Error

Line: 98

                  for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
      // Compute the filter at the same time.
      filter |= 1L << c;
      int index = smear(c) & mask;
      while (true) {
        // Check for empty.
        if (table[index] == 0) {
          table[index] = (char) c;
          break;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'index' (lines '98'-'110').
Error

Line: 98

                  for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
      // Compute the filter at the same time.
      filter |= 1L << c;
      int index = smear(c) & mask;
      while (true) {
        // Check for empty.
        if (table[index] == 0) {
          table[index] = (char) c;
          break;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'index' (lines '106'-'98').
Error

Line: 106

                        break;
        }
        // Linear probing.
        index = (index + 1) & mask;
      }
    }
    return new SmallCharMatcher(table, filter, containsZero, description);
  }


            

Reported by PMD.

Found 'DU'-anomaly for variable 'index' (lines '106'-'110').
Error

Line: 106

                        break;
        }
        // Linear probing.
        index = (index + 1) & mask;
      }
    }
    return new SmallCharMatcher(table, filter, containsZero, description);
  }


            

Reported by PMD.

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

Line: 97

                static final int UNSET_INT = -1;

  // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;

            

Reported by PMD.

Field initialCapacity has the same name as a method
Error

Line: 99

                // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;


            

Reported by PMD.

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

Line: 99

                // TODO(kevinb): dispense with this after benchmarking
  boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;


            

Reported by PMD.

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

Line: 100

                boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

            

Reported by PMD.

Field concurrencyLevel has the same name as a method
Error

Line: 100

                boolean useCustomMap;

  int initialCapacity = UNSET_INT;
  int concurrencyLevel = UNSET_INT;

  @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

            

Reported by PMD.

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

Line: 105

                @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

  /**
   * Constructs a new {@code MapMaker} instance with default settings, including strong keys, strong
   * values, and no automatic eviction of any kind.
   */

            

Reported by PMD.

Field keyEquivalence has the same name as a method
Error

Line: 105

                @CheckForNull Strength keyStrength;
  @CheckForNull Strength valueStrength;

  @CheckForNull Equivalence<Object> keyEquivalence;

  /**
   * Constructs a new {@code MapMaker} instance with default settings, including strong keys, strong
   * values, and no automatic eviction of any kind.
   */

            

Reported by PMD.

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

Line: 130

                }

  Equivalence<Object> getKeyEquivalence() {
    return MoreObjects.firstNonNull(keyEquivalence, getKeyStrength().defaultEquivalence());
  }

  /**
   * Sets the minimum total size for the internal hash tables. For example, if the initial capacity
   * is {@code 60}, and the concurrency level is {@code 8}, then eight segments are created, each

            

Reported by PMD.

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

Line: 309

                  if (keyEquivalence != null) {
      s.addValue("keyEquivalence");
    }
    return s.toString();
  }
}

            

Reported by PMD.

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.

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.

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

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.

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.

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.