The following issues were found

android/guava/src/com/google/common/base/Strings.java
10 issues
Avoid reassigning parameters such as 'template'
Design

Line: 263

                 */
  // TODO(diamondm) consider using Arrays.toString() for array parameters
  public static String lenientFormat(
      @CheckForNull String template, @CheckForNull @Nullable Object... args) {
    template = String.valueOf(template); // null -> "null"

    if (args == null) {
      args = new Object[] {"(Object[])null"};
    } else {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 149

                public static String repeat(String string, int count) {
    checkNotNull(string); // eager for GWT.

    if (count <= 1) {
      checkArgument(count >= 0, "invalid count: %s", count);
      return (count == 0) ? "" : string;
    }

    // IF YOU MODIFY THE CODE HERE, you must update StringsRepeatBenchmark

            

Reported by PMD.

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

Line: 191

                  if (validSurrogatePairAt(a, p - 1) || validSurrogatePairAt(b, p - 1)) {
      p--;
    }
    return a.subSequence(0, p).toString();
  }

  /**
   * Returns the longest string {@code suffix} such that {@code a.toString().endsWith(suffix) &&
   * b.toString().endsWith(suffix)}, taking care not to split surrogate pairs. If {@code a} and

            

Reported by PMD.

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

Line: 214

                      || validSurrogatePairAt(b, b.length() - s - 1)) {
      s--;
    }
    return a.subSequence(a.length() - s, a.length()).toString();
  }

  /**
   * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}.
   * Out-of-range indexes return false.

            

Reported by PMD.

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

Line: 275

                  }

    // start substituting the arguments into the '%s' placeholders
    StringBuilder builder = new StringBuilder(template.length() + 16 * args.length);
    int templateStart = 0;
    int i = 0;
    while (i < args.length) {
      int placeholderStart = template.indexOf("%s", templateStart);
      if (placeholderStart == -1) {

            

Reported by PMD.

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

Line: 287

                    builder.append(args[i++]);
      templateStart = placeholderStart + 2;
    }
    builder.append(template, templateStart, template.length());

    // if we run out of placeholders, append the extra args in square braces
    if (i < args.length) {
      builder.append(" [");
      builder.append(args[i++]);

            

Reported by PMD.

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

Line: 309

                  }
    try {
      return o.toString();
    } catch (Exception e) {
      // Default toString() behavior - see Object.toString()
      String objectToString =
          o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
      // Logger is created inline with fixed name to avoid forcing Proguard to create another class.
      Logger.getLogger("com.google.common.base.Strings")

            

Reported by PMD.

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

Line: 312

                  } catch (Exception e) {
      // Default toString() behavior - see Object.toString()
      String objectToString =
          o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
      // Logger is created inline with fixed name to avoid forcing Proguard to create another class.
      Logger.getLogger("com.google.common.base.Strings")
          .log(WARNING, "Exception during lenientFormat for " + objectToString, e);
      return "<" + objectToString + " threw " + e.getClass().getName() + ">";
    }

            

Reported by PMD.

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

Line: 314

                    String objectToString =
          o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
      // Logger is created inline with fixed name to avoid forcing Proguard to create another class.
      Logger.getLogger("com.google.common.base.Strings")
          .log(WARNING, "Exception during lenientFormat for " + objectToString, e);
      return "<" + objectToString + " threw " + e.getClass().getName() + ">";
    }
  }
}

            

Reported by PMD.

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

Line: 316

                    // Logger is created inline with fixed name to avoid forcing Proguard to create another class.
      Logger.getLogger("com.google.common.base.Strings")
          .log(WARNING, "Exception during lenientFormat for " + objectToString, e);
      return "<" + objectToString + " threw " + e.getClass().getName() + ">";
    }
  }
}

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java
10 issues
Avoid throwing null pointer exceptions.
Design

Line: 58

                  if (!allowNulls) {
      for (Object element : contents) {
        if (element == null) {
          throw new NullPointerException();
        }
      }
    }
  }


            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 74

                  if (!allowNulls) {
      // behave badly
      if (object == null) {
        throw new NullPointerException();
      }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);
  }

            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 87

                    for (Object object : collection) {
        // behave badly
        if (object == null) {
          throw new NullPointerException();
        }
      }
    }
    return super.containsAll(collection);
  }

            

Reported by PMD.

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

Line: 32

               * @author Kevin Bourrillion
 */
@GwtCompatible
public class MinimalCollection<E> extends AbstractCollection<E> {
  // TODO: expose allow nulls parameter?

  public static <E> MinimalCollection<E> of(E... contents) {
    return new MinimalCollection<E>(Object.class, true, contents);
  }

            

Reported by PMD.

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

Line: 44

                  return new MinimalCollection<E>(type, true, contents);
  }

  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {

            

Reported by PMD.

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

Line: 45

                }

  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {
    // TODO: consider making it shuffle the contents to test iteration order.

            

Reported by PMD.

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

Line: 46

              
  private final E[] contents;
  private final Class<? super E> type;
  private final boolean allowNulls;

  // Package-private so that it can be extended.
  MinimalCollection(Class<? super E> type, boolean allowNulls, E... contents) {
    // TODO: consider making it shuffle the contents to test iteration order.
    this.contents = Platform.clone(contents);

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 73

                public boolean contains(Object object) {
    if (!allowNulls) {
      // behave badly
      if (object == null) {
        throw new NullPointerException();
      }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);

            

Reported by PMD.

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

Line: 78

                    }
    }
    Platform.checkCast(type, object); // behave badly
    return Arrays.asList(contents).contains(object);
  }

  @Override
  public boolean containsAll(Collection<?> collection) {
    if (!allowNulls) {

            

Reported by PMD.

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

Line: 96

              
  @Override
  public Iterator<E> iterator() {
    return Arrays.asList(contents).iterator();
  }

  @Override
  public Object[] toArray() {
    Object[] result = new Object[contents.length];

            

Reported by PMD.

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

Line: 36

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class UnmodifiableSortedMultiset<E extends @Nullable Object> extends UnmodifiableMultiset<E>
    implements SortedMultiset<E> {
  UnmodifiableSortedMultiset(SortedMultiset<E> delegate) {
    super(delegate);
  }

  @Override

            

Reported by PMD.

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

Line: 48

              
  @Override
  public Comparator<? super E> comparator() {
    return delegate().comparator();
  }

  @Override
  NavigableSet<E> createElementSet() {
    return Sets.unmodifiableNavigableSet(delegate().elementSet());

            

Reported by PMD.

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

Line: 53

              
  @Override
  NavigableSet<E> createElementSet() {
    return Sets.unmodifiableNavigableSet(delegate().elementSet());
  }

  @Override
  public NavigableSet<E> elementSet() {
    return (NavigableSet<E>) super.elementSet();

            

Reported by PMD.

Field descendingMultiset has the same name as a method
Error

Line: 61

                  return (NavigableSet<E>) super.elementSet();
  }

  @CheckForNull private transient UnmodifiableSortedMultiset<E> descendingMultiset;

  @Override
  public SortedMultiset<E> descendingMultiset() {
    UnmodifiableSortedMultiset<E> result = descendingMultiset;
    if (result == null) {

            

Reported by PMD.

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

Line: 67

                public SortedMultiset<E> descendingMultiset() {
    UnmodifiableSortedMultiset<E> result = descendingMultiset;
    if (result == null) {
      result = new UnmodifiableSortedMultiset<E>(delegate().descendingMultiset());
      result.descendingMultiset = this;
      return descendingMultiset = result;
    }
    return result;
  }

            

Reported by PMD.

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

Line: 77

                @Override
  @CheckForNull
  public Entry<E> firstEntry() {
    return delegate().firstEntry();
  }

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

            

Reported by PMD.

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

Line: 83

                @Override
  @CheckForNull
  public Entry<E> lastEntry() {
    return delegate().lastEntry();
  }

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

            

Reported by PMD.

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

Line: 100

              
  @Override
  public SortedMultiset<E> headMultiset(@ParametricNullness E upperBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().headMultiset(upperBound, boundType));
  }

  @Override
  public SortedMultiset<E> subMultiset(
      @ParametricNullness E lowerBound,

            

Reported by PMD.

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

Line: 110

                    @ParametricNullness E upperBound,
      BoundType upperBoundType) {
    return Multisets.unmodifiableSortedMultiset(
        delegate().subMultiset(lowerBound, lowerBoundType, upperBound, upperBoundType));
  }

  @Override
  public SortedMultiset<E> tailMultiset(@ParametricNullness E lowerBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));

            

Reported by PMD.

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

Line: 115

              
  @Override
  public SortedMultiset<E> tailMultiset(@ParametricNullness E lowerBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));
  }

  private static final long serialVersionUID = 0;
}

            

Reported by PMD.

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/UnmodifiableSortedMultiset.java
10 issues
This class has too many methods, consider refactoring it.
Design

Line: 30

               * @author Louis Wasserman
 */
final class UnmodifiableSortedMultiset<E> extends UnmodifiableMultiset<E>
    implements SortedMultiset<E> {
  UnmodifiableSortedMultiset(SortedMultiset<E> delegate) {
    super(delegate);
  }

  @Override

            

Reported by PMD.

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

Line: 42

              
  @Override
  public Comparator<? super E> comparator() {
    return delegate().comparator();
  }

  @Override
  SortedSet<E> createElementSet() {
    return Collections.unmodifiableSortedSet(delegate().elementSet());

            

Reported by PMD.

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

Line: 47

              
  @Override
  SortedSet<E> createElementSet() {
    return Collections.unmodifiableSortedSet(delegate().elementSet());
  }

  @Override
  public SortedSet<E> elementSet() {
    return (SortedSet<E>) super.elementSet();

            

Reported by PMD.

Field descendingMultiset has the same name as a method
Error

Line: 55

                  return (SortedSet<E>) super.elementSet();
  }

  private transient UnmodifiableSortedMultiset<E> descendingMultiset;

  @Override
  public SortedMultiset<E> descendingMultiset() {
    UnmodifiableSortedMultiset<E> result = descendingMultiset;
    if (result == null) {

            

Reported by PMD.

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

Line: 61

                public SortedMultiset<E> descendingMultiset() {
    UnmodifiableSortedMultiset<E> result = descendingMultiset;
    if (result == null) {
      result = new UnmodifiableSortedMultiset<E>(delegate().descendingMultiset());
      result.descendingMultiset = this;
      return descendingMultiset = result;
    }
    return result;
  }

            

Reported by PMD.

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

Line: 70

              
  @Override
  public Entry<E> firstEntry() {
    return delegate().firstEntry();
  }

  @Override
  public Entry<E> lastEntry() {
    return delegate().lastEntry();

            

Reported by PMD.

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

Line: 75

              
  @Override
  public Entry<E> lastEntry() {
    return delegate().lastEntry();
  }

  @Override
  public Entry<E> pollFirstEntry() {
    throw new UnsupportedOperationException();

            

Reported by PMD.

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

Line: 90

              
  @Override
  public SortedMultiset<E> headMultiset(E upperBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().headMultiset(upperBound, boundType));
  }

  @Override
  public SortedMultiset<E> subMultiset(
      E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) {

            

Reported by PMD.

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

Line: 97

                public SortedMultiset<E> subMultiset(
      E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) {
    return Multisets.unmodifiableSortedMultiset(
        delegate().subMultiset(lowerBound, lowerBoundType, upperBound, upperBoundType));
  }

  @Override
  public SortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));

            

Reported by PMD.

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

Line: 102

              
  @Override
  public SortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) {
    return Multisets.unmodifiableSortedMultiset(delegate().tailMultiset(lowerBound, boundType));
  }

  private static final long serialVersionUID = 0;
}

            

Reported by PMD.

android/guava/src/com/google/common/collect/ImmutableMapValues.java
10 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 33

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
  private final ImmutableMap<K, V> map;

  ImmutableMapValues(ImmutableMap<K, V> map) {
    this.map = map;
  }

            

Reported by PMD.

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

Line: 34

              @GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
  private final ImmutableMap<K, V> map;

  ImmutableMapValues(ImmutableMap<K, V> map) {
    this.map = map;
  }


            

Reported by PMD.

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

Line: 57

              
      @Override
      public V next() {
        return entryItr.next().getValue();
      }
    };
  }

  @Override

            

Reported by PMD.

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

Line: 74

              
  @Override
  public ImmutableList<V> asList() {
    final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
    return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

            

Reported by PMD.

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

Line: 78

                  return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

      @Override
      boolean isPartialView() {
        return true;

            

Reported by PMD.

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

Line: 101

              
  @GwtIncompatible // serialization
  private static class SerializedForm<V> implements Serializable {
    final ImmutableMap<?, V> map;

    SerializedForm(ImmutableMap<?, V> map) {
      this.map = map;
    }


            

Reported by PMD.

Found 'DU'-anomaly for variable 'entryList' (lines '74'-'91').
Error

Line: 74

              
  @Override
  public ImmutableList<V> asList() {
    final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
    return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entryList' (lines '74'-'91').
Error

Line: 74

              
  @Override
  public ImmutableList<V> asList() {
    final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
    return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entryList' (lines '74'-'91').
Error

Line: 74

              
  @Override
  public ImmutableList<V> asList() {
    final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
    return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'entryList' (lines '74'-'91').
Error

Line: 74

              
  @Override
  public ImmutableList<V> asList() {
    final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList();
    return new ImmutableList<V>() {
      @Override
      public V get(int index) {
        return entryList.get(index).getValue();
      }

            

Reported by PMD.

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

Line: 29

              @GwtCompatible(serializable = true)
@SuppressWarnings({"unchecked", "rawtypes"}) // TODO(kevinb): the right way to explain this??
@ElementTypesAreNonnullByDefault
final class ReverseNaturalOrdering extends Ordering<Comparable<?>> implements Serializable {
  static final ReverseNaturalOrdering INSTANCE = new ReverseNaturalOrdering();

  @Override
  public int compare(Comparable<?> left, Comparable<?> right) {
    checkNotNull(left); // right null is caught later

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 35

                @Override
  public int compare(Comparable<?> left, Comparable<?> right) {
    checkNotNull(left); // right null is caught later
    if (left == right) {
      return 0;
    }

    return ((Comparable<Object>) right).compareTo(left);
  }

            

Reported by PMD.

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

Line: 51

              
  @Override
  public <E extends Comparable<?>> E min(E a, E b) {
    return NaturalOrdering.INSTANCE.max(a, b);
  }

  @Override
  public <E extends Comparable<?>> E min(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.max(a, b, c, rest);

            

Reported by PMD.

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

Line: 56

              
  @Override
  public <E extends Comparable<?>> E min(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.max(a, b, c, rest);
  }

  @Override
  public <E extends Comparable<?>> E min(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.max(iterator);

            

Reported by PMD.

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

Line: 61

              
  @Override
  public <E extends Comparable<?>> E min(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.max(iterator);
  }

  @Override
  public <E extends Comparable<?>> E min(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.max(iterable);

            

Reported by PMD.

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

Line: 66

              
  @Override
  public <E extends Comparable<?>> E min(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.max(iterable);
  }

  @Override
  public <E extends Comparable<?>> E max(E a, E b) {
    return NaturalOrdering.INSTANCE.min(a, b);

            

Reported by PMD.

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

Line: 71

              
  @Override
  public <E extends Comparable<?>> E max(E a, E b) {
    return NaturalOrdering.INSTANCE.min(a, b);
  }

  @Override
  public <E extends Comparable<?>> E max(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.min(a, b, c, rest);

            

Reported by PMD.

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

Line: 76

              
  @Override
  public <E extends Comparable<?>> E max(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.min(a, b, c, rest);
  }

  @Override
  public <E extends Comparable<?>> E max(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.min(iterator);

            

Reported by PMD.

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

Line: 81

              
  @Override
  public <E extends Comparable<?>> E max(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.min(iterator);
  }

  @Override
  public <E extends Comparable<?>> E max(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.min(iterable);

            

Reported by PMD.

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

Line: 86

              
  @Override
  public <E extends Comparable<?>> E max(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.min(iterable);
  }

  // preserving singleton-ness gives equals()/hashCode() for free
  private Object readResolve() {
    return INSTANCE;

            

Reported by PMD.

android/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java
10 issues
The class 'AbstractCompositeHashFunction' has a Standard Cyclomatic Complexity of 8 (Highest = 30).
Design

Line: 34

               */
@Immutable
@ElementTypesAreNonnullByDefault
abstract class AbstractCompositeHashFunction extends AbstractHashFunction {

  @SuppressWarnings("Immutable") // array not modified after creation
  final HashFunction[] functions;

  AbstractCompositeHashFunction(HashFunction... functions) {

            

Reported by PMD.

The class 'AbstractCompositeHashFunction' has a Modified Cyclomatic Complexity of 8 (Highest = 30).
Design

Line: 34

               */
@Immutable
@ElementTypesAreNonnullByDefault
abstract class AbstractCompositeHashFunction extends AbstractHashFunction {

  @SuppressWarnings("Immutable") // array not modified after creation
  final HashFunction[] functions;

  AbstractCompositeHashFunction(HashFunction... functions) {

            

Reported by PMD.

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

Line: 37

              abstract class AbstractCompositeHashFunction extends AbstractHashFunction {

  @SuppressWarnings("Immutable") // array not modified after creation
  final HashFunction[] functions;

  AbstractCompositeHashFunction(HashFunction... functions) {
    for (HashFunction function : functions) {
      checkNotNull(function);
    }

            

Reported by PMD.

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

Line: 39

                @SuppressWarnings("Immutable") // array not modified after creation
  final HashFunction[] functions;

  AbstractCompositeHashFunction(HashFunction... functions) {
    for (HashFunction function : functions) {
      checkNotNull(function);
    }
    this.functions = functions;
  }

            

Reported by PMD.

The method 'fromHashers' has a Modified Cyclomatic Complexity of 30.
Design

Line: 73

                  return fromHashers(hashers);
  }

  private Hasher fromHashers(final Hasher[] hashers) {
    return new Hasher() {
      @Override
      public Hasher putByte(byte b) {
        for (Hasher hasher : hashers) {
          hasher.putByte(b);

            

Reported by PMD.

The method 'fromHashers(Hasher)' has an NPath complexity of 16384, current threshold is 200
Design

Line: 73

                  return fromHashers(hashers);
  }

  private Hasher fromHashers(final Hasher[] hashers) {
    return new Hasher() {
      @Override
      public Hasher putByte(byte b) {
        for (Hasher hasher : hashers) {
          hasher.putByte(b);

            

Reported by PMD.

The method 'fromHashers' has a Standard Cyclomatic Complexity of 30.
Design

Line: 73

                  return fromHashers(hashers);
  }

  private Hasher fromHashers(final Hasher[] hashers) {
    return new Hasher() {
      @Override
      public Hasher putByte(byte b) {
        for (Hasher hasher : hashers) {
          hasher.putByte(b);

            

Reported by PMD.

Avoid really long methods.
Design

Line: 73

                  return fromHashers(hashers);
  }

  private Hasher fromHashers(final Hasher[] hashers) {
    return new Hasher() {
      @Override
      public Hasher putByte(byte b) {
        for (Hasher hasher : hashers) {
          hasher.putByte(b);

            

Reported by PMD.

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

Line: 52

                 * hashers are the same order as the functions given to the constructor.
   */
  // this could be cleaner if it passed HashCode[], but that would create yet another array...
  /* protected */ abstract HashCode makeHash(Hasher[] hashers);

  @Override
  public Hasher newHasher() {
    Hasher[] hashers = new Hasher[functions.length];
    for (int i = 0; i < hashers.length; i++) {

            

Reported by PMD.

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

Line: 73

                  return fromHashers(hashers);
  }

  private Hasher fromHashers(final Hasher[] hashers) {
    return new Hasher() {
      @Override
      public Hasher putByte(byte b) {
        for (Hasher hasher : hashers) {
          hasher.putByte(b);

            

Reported by PMD.

guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/TestPlatform.java
10 issues
Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 34

                  try {
      future.get();
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }


            

Reported by PMD.

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

Line: 35

                    future.get();
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyTimedGetOnPendingFuture(Future<?> future) {

            

Reported by PMD.

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

Line: 36

                    fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyTimedGetOnPendingFuture(Future<?> future) {
    try {

            

Reported by PMD.

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

Line: 36

                    fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyTimedGetOnPendingFuture(Future<?> future) {
    try {

            

Reported by PMD.

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

Line: 44

                  try {
      future.get(0, SECONDS);
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }


            

Reported by PMD.

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

Line: 45

                    future.get(0, SECONDS);
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyThreadWasNotInterrupted() {

            

Reported by PMD.

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

Line: 46

                    fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyThreadWasNotInterrupted() {
    // There is no thread interruption in GWT, so there's nothing to do.

            

Reported by PMD.

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

Line: 46

                    fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
      assertThat(e).hasMessageThat().isEqualTo("Cannot get() on a pending future.");
    }
  }

  static void verifyThreadWasNotInterrupted() {
    // There is no thread interruption in GWT, so there's nothing to do.

            

Reported by PMD.

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

Line: 63

                  try {
      return future.get(0, SECONDS);
    } catch (InterruptedException e) {
      throw new AssertionError();
    } catch (TimeoutException e) {
      throw new AssertionError();
    }
  }


            

Reported by PMD.

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

Line: 65

                  } catch (InterruptedException e) {
      throw new AssertionError();
    } catch (TimeoutException e) {
      throw new AssertionError();
    }
  }

  private TestPlatform() {}
}

            

Reported by PMD.

guava/src/com/google/common/primitives/UnsignedBytes.java
10 issues
Avoid throwing raw exception types.
Design

Line: 329

                          && (BYTE_ARRAY_BASE_OFFSET % 8) == 0
            // sanity check - this should never fail
            && theUnsafe.arrayIndexScale(byte[].class) == 1)) {
          throw new Error(); // force fallback to PureJavaComparator
        }
      }

      /**
       * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 362

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

      @Override
      public int compare(byte[] left, byte[] right) {

            

Reported by PMD.

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

Line: 48

               */
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class UnsignedBytes {
  private UnsignedBytes() {}

  /**
   * The largest power of two that can be represented as an unsigned {@code byte}.
   *

            

Reported by PMD.

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

                 * available.
   */
  @VisibleForTesting
  static class LexicographicalComparatorHolder {
    static final String UNSAFE_COMPARATOR_NAME =
        LexicographicalComparatorHolder.class.getName() + "$UnsafeComparator";

    static final Comparator<byte[]> BEST_COMPARATOR = getBestComparator();


            

Reported by PMD.

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

Line: 341

                     */
      private static sun.misc.Unsafe getUnsafe() {
        try {
          return sun.misc.Unsafe.getUnsafe();
        } catch (SecurityException e) {
          // that's okay; try reflection instead
        }
        try {
          return java.security.AccessController.doPrivileged(

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 342

                    private static sun.misc.Unsafe getUnsafe() {
        try {
          return sun.misc.Unsafe.getUnsafe();
        } catch (SecurityException e) {
          // that's okay; 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: 362

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

      @Override
      public int compare(byte[] left, byte[] right) {

            

Reported by PMD.

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

Line: 443

                      Class<?> theClass = Class.forName(UNSAFE_COMPARATOR_NAME);

        // requireNonNull is safe because the class is an enum.
        Object[] constants = requireNonNull(theClass.getEnumConstants());

        // yes, UnsafeComparator does implement Comparator<byte[]>
        @SuppressWarnings("unchecked")
        Comparator<byte[]> comparator = (Comparator<byte[]>) constants[0];
        return comparator;

            

Reported by PMD.

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

Line: 449

                      @SuppressWarnings("unchecked")
        Comparator<byte[]> comparator = (Comparator<byte[]>) constants[0];
        return comparator;
      } catch (Throwable t) { // ensure we really catch *everything*
        return lexicographicalComparatorJavaImpl();
      }
    }
  }


            

Reported by PMD.

Avoid importing anything from the sun.* packages
Error

Line: 29

              import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Comparator;
import sun.misc.Unsafe;

/**
 * Static utility methods pertaining to {@code byte} primitives that interpret values as
 * <i>unsigned</i> (that is, any negative value {@code b} is treated as the positive value {@code
 * 256 + b}). The corresponding methods that treat the values as signed are found in {@link

            

Reported by PMD.

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

Line: 29

              @GwtCompatible(serializable = true)
@SuppressWarnings({"unchecked", "rawtypes"}) // TODO(kevinb): the right way to explain this??
@ElementTypesAreNonnullByDefault
final class ReverseNaturalOrdering extends Ordering<Comparable<?>> implements Serializable {
  static final ReverseNaturalOrdering INSTANCE = new ReverseNaturalOrdering();

  @Override
  public int compare(Comparable<?> left, Comparable<?> right) {
    checkNotNull(left); // right null is caught later

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 35

                @Override
  public int compare(Comparable<?> left, Comparable<?> right) {
    checkNotNull(left); // right null is caught later
    if (left == right) {
      return 0;
    }

    return ((Comparable<Object>) right).compareTo(left);
  }

            

Reported by PMD.

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

Line: 51

              
  @Override
  public <E extends Comparable<?>> E min(E a, E b) {
    return NaturalOrdering.INSTANCE.max(a, b);
  }

  @Override
  public <E extends Comparable<?>> E min(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.max(a, b, c, rest);

            

Reported by PMD.

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

Line: 56

              
  @Override
  public <E extends Comparable<?>> E min(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.max(a, b, c, rest);
  }

  @Override
  public <E extends Comparable<?>> E min(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.max(iterator);

            

Reported by PMD.

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

Line: 61

              
  @Override
  public <E extends Comparable<?>> E min(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.max(iterator);
  }

  @Override
  public <E extends Comparable<?>> E min(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.max(iterable);

            

Reported by PMD.

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

Line: 66

              
  @Override
  public <E extends Comparable<?>> E min(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.max(iterable);
  }

  @Override
  public <E extends Comparable<?>> E max(E a, E b) {
    return NaturalOrdering.INSTANCE.min(a, b);

            

Reported by PMD.

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

Line: 71

              
  @Override
  public <E extends Comparable<?>> E max(E a, E b) {
    return NaturalOrdering.INSTANCE.min(a, b);
  }

  @Override
  public <E extends Comparable<?>> E max(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.min(a, b, c, rest);

            

Reported by PMD.

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

Line: 76

              
  @Override
  public <E extends Comparable<?>> E max(E a, E b, E c, E... rest) {
    return NaturalOrdering.INSTANCE.min(a, b, c, rest);
  }

  @Override
  public <E extends Comparable<?>> E max(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.min(iterator);

            

Reported by PMD.

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

Line: 81

              
  @Override
  public <E extends Comparable<?>> E max(Iterator<E> iterator) {
    return NaturalOrdering.INSTANCE.min(iterator);
  }

  @Override
  public <E extends Comparable<?>> E max(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.min(iterable);

            

Reported by PMD.

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

Line: 86

              
  @Override
  public <E extends Comparable<?>> E max(Iterable<E> iterable) {
    return NaturalOrdering.INSTANCE.min(iterable);
  }

  // preserving singleton-ness gives equals()/hashCode() for free
  private Object readResolve() {
    return INSTANCE;

            

Reported by PMD.