The following issues were found

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

Line: 40

              @Immutable(containerOf = "B")
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ImmutableClassToInstanceMap<B> extends ForwardingMap<Class<? extends B>, B>
    implements ClassToInstanceMap<B>, Serializable {

  private static final ImmutableClassToInstanceMap<Object> EMPTY =
      new ImmutableClassToInstanceMap<>(ImmutableMap.<Class<?>, Object>of());


            

Reported by PMD.

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

Line: 94

                 * @since 2.0
   */
  public static final class Builder<B> {
    private final ImmutableMap.Builder<Class<? extends B>, B> mapBuilder = ImmutableMap.builder();

    /**
     * Associates {@code key} with {@code value} in the built map. Duplicate keys are not allowed,
     * and will cause {@link #build} to fail.
     */

            

Reported by PMD.

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

Line: 124

                  }

    private static <B, T extends B> T cast(Class<T> type, B value) {
      return Primitives.wrap(type).cast(value);
    }

    /**
     * Returns a new immutable class-to-instance map containing the entries provided to this
     * builder.

            

Reported by PMD.

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

Line: 135

                   */
    public ImmutableClassToInstanceMap<B> build() {
      ImmutableMap<Class<? extends B>, B> map = mapBuilder.build();
      if (map.isEmpty()) {
        return of();
      } else {
        return new ImmutableClassToInstanceMap<B>(map);
      }
    }

            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 164

                  return new Builder<B>().putAll(map).build();
  }

  private final ImmutableMap<Class<? extends B>, B> delegate;

  private ImmutableClassToInstanceMap(ImmutableMap<Class<? extends B>, B> delegate) {
    this.delegate = delegate;
  }


            

Reported by PMD.

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

Line: 164

                  return new Builder<B>().putAll(map).build();
  }

  private final ImmutableMap<Class<? extends B>, B> delegate;

  private ImmutableClassToInstanceMap(ImmutableMap<Class<? extends B>, B> delegate) {
    this.delegate = delegate;
  }


            

Reported by PMD.

guava/src/com/google/common/util/concurrent/WrappingExecutorService.java
6 issues
Avoid throwing raw exception types.
Design

Line: 73

                        wrapped.call();
        } catch (Exception e) {
          throwIfUnchecked(e);
          throw new RuntimeException(e);
        }
      }
    };
  }


            

Reported by PMD.

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

Line: 47

              @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict.
@GwtIncompatible
@ElementTypesAreNonnullByDefault
abstract class WrappingExecutorService implements ExecutorService {
  private final ExecutorService delegate;

  protected WrappingExecutorService(ExecutorService delegate) {
    this.delegate = checkNotNull(delegate);
  }

            

Reported by PMD.

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

Line: 48

              @GwtIncompatible
@ElementTypesAreNonnullByDefault
abstract class WrappingExecutorService implements ExecutorService {
  private final ExecutorService delegate;

  protected WrappingExecutorService(ExecutorService delegate) {
    this.delegate = checkNotNull(delegate);
  }


            

Reported by PMD.

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

Line: 71

                    public void run() {
        try {
          wrapped.call();
        } catch (Exception e) {
          throwIfUnchecked(e);
          throw new RuntimeException(e);
        }
      }
    };

            

Reported by PMD.

Found 'DU'-anomaly for variable 'wrapped' (lines '65'-'77').
Error

Line: 65

                 * delegates to {@link #wrapTask(Callable)}.
   */
  protected Runnable wrapTask(Runnable command) {
    final Callable<Object> wrapped = wrapTask(Executors.callable(command, null));
    return new Runnable() {
      @Override
      public void run() {
        try {
          wrapped.call();

            

Reported by PMD.

Found 'DU'-anomaly for variable 'wrapped' (lines '65'-'77').
Error

Line: 65

                 * delegates to {@link #wrapTask(Callable)}.
   */
  protected Runnable wrapTask(Runnable command) {
    final Callable<Object> wrapped = wrapTask(Executors.callable(command, null));
    return new Runnable() {
      @Override
      public void run() {
        try {
          wrapped.call();

            

Reported by PMD.

guava/src/com/google/common/escape/ArrayBasedCharEscaper.java
6 issues
Avoid reassigning parameters such as 'safeMax'
Design

Line: 87

                 * @param safeMin the lowest character value in the safe range
   * @param safeMax the highest character value in the safe range
   */
  protected ArrayBasedCharEscaper(ArrayBasedEscaperMap escaperMap, char safeMin, char safeMax) {

    checkNotNull(escaperMap); // GWT specific check (do not optimize)
    this.replacements = escaperMap.getReplacementArray();
    this.replacementsLength = replacements.length;
    if (safeMax < safeMin) {

            

Reported by PMD.

Avoid reassigning parameters such as 'safeMin'
Design

Line: 87

                 * @param safeMin the lowest character value in the safe range
   * @param safeMax the highest character value in the safe range
   */
  protected ArrayBasedCharEscaper(ArrayBasedEscaperMap escaperMap, char safeMin, char safeMax) {

    checkNotNull(escaperMap); // GWT specific check (do not optimize)
    this.replacements = escaperMap.getReplacementArray();
    this.replacementsLength = replacements.length;
    if (safeMax < safeMin) {

            

Reported by PMD.

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

Line: 49

              @ElementTypesAreNonnullByDefault
public abstract class ArrayBasedCharEscaper extends CharEscaper {
  // The replacement array (see ArrayBasedEscaperMap).
  private final char[][] replacements;
  // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first character in the safe range.
  private final char safeMin;
  // The last character in the safe range.

            

Reported by PMD.

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

Line: 51

                // The replacement array (see ArrayBasedEscaperMap).
  private final char[][] replacements;
  // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first character in the safe range.
  private final char safeMin;
  // The last character in the safe range.
  private final char safeMax;


            

Reported by PMD.

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

Line: 53

                // The number of elements in the replacement array.
  private final int replacementsLength;
  // The first character in the safe range.
  private final char safeMin;
  // The last character in the safe range.
  private final char safeMax;

  /**
   * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe

            

Reported by PMD.

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

Line: 55

                // The first character in the safe range.
  private final char safeMin;
  // The last character in the safe range.
  private final char safeMax;

  /**
   * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe
   * range. If {@code safeMax < safeMin} then no characters are considered safe.
   *

            

Reported by PMD.

guava/src/com/google/common/escape/ArrayBasedEscaperMap.java
6 issues
Returning 'replacementArray' may expose an internal array.
Design

Line: 63

              
  // Returns the non-null array of replacements for fast lookup.
  char[][] getReplacementArray() {
    return replacementArray;
  }

  // Creates a replacement array from the given map. The returned array is a
  // linear lookup table of replacement character sequences indexed by the
  // original character value.

            

Reported by PMD.

Returning 'EMPTY_REPLACEMENT_ARRAY' may expose an internal array.
Design

Line: 73

                static char[][] createReplacementArray(Map<Character, String> map) {
    checkNotNull(map); // GWT specific check (do not optimize)
    if (map.isEmpty()) {
      return EMPTY_REPLACEMENT_ARRAY;
    }
    char max = Collections.max(map.keySet());
    char[][] replacements = new char[max + 1][];
    for (Character c : map.keySet()) {
      replacements[c] = map.get(c).toCharArray();

            

Reported by PMD.

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

Line: 78

                  char max = Collections.max(map.keySet());
    char[][] replacements = new char[max + 1][];
    for (Character c : map.keySet()) {
      replacements[c] = map.get(c).toCharArray();
    }
    return replacements;
  }

  // Immutable empty array for when there are no replacements.

            

Reported by PMD.

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

Line: 57

                // instances.
  private final char[][] replacementArray;

  private ArrayBasedEscaperMap(char[][] replacementArray) {
    this.replacementArray = replacementArray;
  }

  // Returns the non-null array of replacements for fast lookup.
  char[][] getReplacementArray() {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'replacements' (lines '76'-'78').
Error

Line: 76

                    return EMPTY_REPLACEMENT_ARRAY;
    }
    char max = Collections.max(map.keySet());
    char[][] replacements = new char[max + 1][];
    for (Character c : map.keySet()) {
      replacements[c] = map.get(c).toCharArray();
    }
    return replacements;
  }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'replacements' (lines '78'-'78').
Error

Line: 78

                  char max = Collections.max(map.keySet());
    char[][] replacements = new char[max + 1][];
    for (Character c : map.keySet()) {
      replacements[c] = map.get(c).toCharArray();
    }
    return replacements;
  }

  // Immutable empty array for when there are no replacements.

            

Reported by PMD.

guava/src/com/google/common/graph/AbstractGraph.java
6 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 44

                  }
    Graph<?> other = (Graph<?>) obj;

    return isDirected() == other.isDirected()
        && nodes().equals(other.nodes())
        && edges().equals(other.edges());
  }

  @Override

            

Reported by PMD.

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

Line: 45

                  Graph<?> other = (Graph<?>) obj;

    return isDirected() == other.isDirected()
        && nodes().equals(other.nodes())
        && edges().equals(other.edges());
  }

  @Override
  public final int hashCode() {

            

Reported by PMD.

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

Line: 45

                  Graph<?> other = (Graph<?>) obj;

    return isDirected() == other.isDirected()
        && nodes().equals(other.nodes())
        && edges().equals(other.edges());
  }

  @Override
  public final int hashCode() {

            

Reported by PMD.

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

Line: 46

              
    return isDirected() == other.isDirected()
        && nodes().equals(other.nodes())
        && edges().equals(other.edges());
  }

  @Override
  public final int hashCode() {
    return edges().hashCode();

            

Reported by PMD.

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

Line: 46

              
    return isDirected() == other.isDirected()
        && nodes().equals(other.nodes())
        && edges().equals(other.edges());
  }

  @Override
  public final int hashCode() {
    return edges().hashCode();

            

Reported by PMD.

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

Line: 51

              
  @Override
  public final int hashCode() {
    return edges().hashCode();
  }

  /** Returns a string representation of this graph. */
  @Override
  public String toString() {

            

Reported by PMD.

guava/src/com/google/common/collect/ForwardingListIterator.java
6 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 52

              
  @Override
  public void add(@ParametricNullness E element) {
    delegate().add(element);
  }

  @Override
  public boolean hasPrevious() {
    return delegate().hasPrevious();

            

Reported by PMD.

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

Line: 57

              
  @Override
  public boolean hasPrevious() {
    return delegate().hasPrevious();
  }

  @Override
  public int nextIndex() {
    return delegate().nextIndex();

            

Reported by PMD.

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

Line: 62

              
  @Override
  public int nextIndex() {
    return delegate().nextIndex();
  }

  @CanIgnoreReturnValue
  @Override
  @ParametricNullness

            

Reported by PMD.

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

Line: 69

                @Override
  @ParametricNullness
  public E previous() {
    return delegate().previous();
  }

  @Override
  public int previousIndex() {
    return delegate().previousIndex();

            

Reported by PMD.

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

Line: 74

              
  @Override
  public int previousIndex() {
    return delegate().previousIndex();
  }

  @Override
  public void set(@ParametricNullness E element) {
    delegate().set(element);

            

Reported by PMD.

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

Line: 79

              
  @Override
  public void set(@ParametricNullness E element) {
    delegate().set(element);
  }
}

            

Reported by PMD.

guava/src/com/google/common/graph/MapIteratorCache.java
6 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 46

               */
@ElementTypesAreNonnullByDefault
class MapIteratorCache<K, V> {
  private final Map<K, V> backingMap;

  /*
   * Per JDK: "the behavior of a map entry is undefined if the backing map has been modified after
   * the entry was returned by the iterator, except through the setValue operation on the map entry"
   * As such, this field must be cleared before every map mutation.

            

Reported by PMD.

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

Line: 111

                  return new AbstractSet<K>() {
      @Override
      public UnmodifiableIterator<K> iterator() {
        final Iterator<Entry<K, V>> entryIterator = backingMap.entrySet().iterator();

        return new UnmodifiableIterator<K>() {
          @Override
          public boolean hasNext() {
            return entryIterator.hasNext();

            

Reported by PMD.

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

Line: 123

                        public K next() {
            Entry<K, V> entry = entryIterator.next(); // store local reference for thread-safety
            cacheEntry = entry;
            return entry.getKey();
          }
        };
      }

      @Override

            

Reported by PMD.

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

Line: 147

                  Entry<K, V> entry = cacheEntry; // store local reference for thread-safety

    // Check cache. We use == on purpose because it's cheaper and a cache miss is ok.
    if (entry != null && entry.getKey() == key) {
      return entry.getValue();
    }
    return null;
  }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 147

                  Entry<K, V> entry = cacheEntry; // store local reference for thread-safety

    // Check cache. We use == on purpose because it's cheaper and a cache miss is ok.
    if (entry != null && entry.getKey() == key) {
      return entry.getValue();
    }
    return null;
  }


            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 154

                }

  void clearCache() {
    cacheEntry = null;
  }
}

            

Reported by PMD.

guava/src/com/google/common/graph/MapRetrievalCache.java
6 issues
Use equals() to compare object references.
Error

Line: 73

              
    // Check cache. We use == on purpose because it's cheaper and a cache miss is ok.
    entry = cacheEntry1;
    if (entry != null && entry.key == key) {
      return entry.value;
    }
    entry = cacheEntry2;
    if (entry != null && entry.key == key) {
      // Promote second cache entry to first so the access pattern

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 77

                    return entry.value;
    }
    entry = cacheEntry2;
    if (entry != null && entry.key == key) {
      // Promote second cache entry to first so the access pattern
      // [K1, K2, K1, K3, K1, K4...] still hits the cache half the time.
      addToCache(entry);
      return entry.value;
    }

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 89

                @Override
  void clearCache() {
    super.clearCache();
    cacheEntry1 = null;
    cacheEntry2 = null;
  }

  private void addToCache(K key, V value) {
    addToCache(new CacheEntry<K, V>(key, value));

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 90

                void clearCache() {
    super.clearCache();
    cacheEntry1 = null;
    cacheEntry2 = null;
  }

  private void addToCache(K key, V value) {
    addToCache(new CacheEntry<K, V>(key, value));
  }

            

Reported by PMD.

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

Line: 104

                }

  private static final class CacheEntry<K, V> {
    final K key;
    final V value;

    CacheEntry(K key, V value) {
      this.key = key;
      this.value = value;

            

Reported by PMD.

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

Line: 105

              
  private static final class CacheEntry<K, V> {
    final K key;
    final V value;

    CacheEntry(K key, V value) {
      this.key = key;
      this.value = value;
    }

            

Reported by PMD.

guava/src/com/google/common/hash/Funnels.java
6 issues
Classes implementing Serializable should set a serialVersionUID
Error

Line: 90

                  return new StringCharsetFunnel(charset);
  }

  private static class StringCharsetFunnel implements Funnel<CharSequence>, Serializable {
    private final Charset charset;

    StringCharsetFunnel(Charset charset) {
      this.charset = Preconditions.checkNotNull(charset);
    }

            

Reported by PMD.

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

Line: 91

                }

  private static class StringCharsetFunnel implements Funnel<CharSequence>, Serializable {
    private final Charset charset;

    StringCharsetFunnel(Charset charset) {
      this.charset = Preconditions.checkNotNull(charset);
    }


            

Reported by PMD.

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

Line: 126

                  }

    private static class SerializedForm implements Serializable {
      private final String charsetCanonicalName;

      SerializedForm(Charset charset) {
        this.charsetCanonicalName = charset.name();
      }


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 174

                  return new SequentialFunnel<E>(elementFunnel);
  }

  private static class SequentialFunnel<E extends @Nullable Object>
      implements Funnel<Iterable<? extends E>>, Serializable {
    private final Funnel<E> elementFunnel;

    SequentialFunnel(Funnel<E> elementFunnel) {
      this.elementFunnel = Preconditions.checkNotNull(elementFunnel);

            

Reported by PMD.

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

Line: 176

              
  private static class SequentialFunnel<E extends @Nullable Object>
      implements Funnel<Iterable<? extends E>>, Serializable {
    private final Funnel<E> elementFunnel;

    SequentialFunnel(Funnel<E> elementFunnel) {
      this.elementFunnel = Preconditions.checkNotNull(elementFunnel);
    }


            

Reported by PMD.

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

Line: 247

                }

  private static class SinkAsStream extends OutputStream {
    final PrimitiveSink sink;

    SinkAsStream(PrimitiveSink sink) {
      this.sink = Preconditions.checkNotNull(sink);
    }


            

Reported by PMD.

refactorings/TraverserRewrite.java
6 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 35

              
    @BeforeTemplate
    Iterable<N> before1(N root) {
      return TreeTraverser.using((N node) -> getChildren(node)).preOrderTraversal(root);
    }

    @BeforeTemplate
    Iterable<N> before2(N root) {
      return new TreeTraverser<N>() {

            

Reported by PMD.

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

Line: 50

              
    @AfterTemplate
    Iterable<N> after(N root) {
      return Traverser.forTree((N node) -> getChildren(node)).depthFirstPreOrder(root);
    }
  }

  abstract class TreeTraverserPostOrder<N> {
    @Placeholder

            

Reported by PMD.

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

Line: 60

              
    @BeforeTemplate
    Iterable<N> before1(N root) {
      return TreeTraverser.using((N node) -> getChildren(node)).postOrderTraversal(root);
    }

    @BeforeTemplate
    Iterable<N> before2(N root) {
      return new TreeTraverser<N>() {

            

Reported by PMD.

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

Line: 75

              
    @AfterTemplate
    Iterable<N> after(N root) {
      return Traverser.forTree((N node) -> getChildren(node)).depthFirstPostOrder(root);
    }
  }

  abstract class TreeTraverserBreadthFirst<N> {
    @Placeholder

            

Reported by PMD.

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

Line: 85

              
    @BeforeTemplate
    Iterable<N> before1(N root) {
      return TreeTraverser.using((N node) -> getChildren(node)).breadthFirstTraversal(root);
    }

    @BeforeTemplate
    Iterable<N> before2(N root) {
      return new TreeTraverser<N>() {

            

Reported by PMD.

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

Line: 100

              
    @AfterTemplate
    Iterable<N> after(N root) {
      return Traverser.forTree((N node) -> getChildren(node)).breadthFirst(root);
    }
  }
}

            

Reported by PMD.