The following issues were found

guava/src/com/google/common/reflect/ClassPath.java
50 issues
Logger calls should be surrounded by log level guards.
Design

Line: 467

                        return;
        }
      } catch (SecurityException e) {
        logger.warning("Cannot access " + file + ": " + e);
        // TODO(emcmanus): consider whether to log other failure cases too.
        return;
      }
      if (file.isDirectory()) {
        scanDirectory(file, builder);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 542

                      throws IOException {
      File[] files = directory.listFiles();
      if (files == null) {
        logger.warning("Cannot read directory " + directory);
        // IO error, just skip the directory
        return;
      }
      for (File f : files) {
        String name = f.getName();

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 606

                        url = getClassPathEntry(jarFile, path);
        } catch (MalformedURLException e) {
          // Ignore bad entry
          logger.warning("Invalid Class-Path entry: " + path);
          continue;
        }
        if (url.getProtocol().equals("file")) {
          builder.add(toFile(url));
        }

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 661

                        urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
        }
      } catch (MalformedURLException e) {
        logger.log(WARNING, "malformed classpath entry: " + entry, e);
      }
    }
    return urls.build();
  }


            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.reflect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH;
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;

            

Reported by PMD.

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

Line: 160

                 * @since 16.0
   */
  public ImmutableSet<ClassInfo> getAllClasses() {
    return FluentIterable.from(resources).filter(ClassInfo.class).toSet();
  }

  /**
   * Returns all top level classes loadable from the current class path. Note that "top-level-ness"
   * is determined heuristically by class name (see {@link ClassInfo#isTopLevel}).

            

Reported by PMD.

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

Line: 160

                 * @since 16.0
   */
  public ImmutableSet<ClassInfo> getAllClasses() {
    return FluentIterable.from(resources).filter(ClassInfo.class).toSet();
  }

  /**
   * Returns all top level classes loadable from the current class path. Note that "top-level-ness"
   * is determined heuristically by class name (see {@link ClassInfo#isTopLevel}).

            

Reported by PMD.

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

Line: 185

                  checkNotNull(packageName);
    ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
    for (ClassInfo classInfo : getTopLevelClasses()) {
      if (classInfo.getPackageName().equals(packageName)) {
        builder.add(classInfo);
      }
    }
    return builder.build();
  }

            

Reported by PMD.

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

Line: 201

                  String packagePrefix = packageName + '.';
    ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
    for (ClassInfo classInfo : getTopLevelClasses()) {
      if (classInfo.getName().startsWith(packagePrefix)) {
        builder.add(classInfo);
      }
    }
    return builder.build();
  }

            

Reported by PMD.

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

Line: 219

                  private final File file;
    private final String resourceName;

    final ClassLoader loader;

    static ResourceInfo of(File file, String resourceName, ClassLoader loader) {
      if (resourceName.endsWith(CLASS_FILE_NAME_EXTENSION)) {
        return new ClassInfo(file, resourceName, loader);
      } else {

            

Reported by PMD.

android/guava/src/com/google/common/reflect/TypeResolver.java
50 issues
The class 'TypeResolver' has a Standard Cyclomatic Complexity of 3 (Highest = 15).
Design

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

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

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

The class 'TypeResolver' has a Modified Cyclomatic Complexity of 3 (Highest = 15).
Design

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

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

Line: 58

              @ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();
  }


            

Reported by PMD.

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

Line: 91

                 * <capture-of-? extends Object>}, effectively preventing {@code set} from accepting any type.
   */
  static TypeResolver invariantly(Type contextType) {
    Type invariantContext = WildcardCapturer.INSTANCE.capture(contextType);
    return new TypeResolver().where(TypeMappingIntrospector.getTypeMappings(invariantContext));
  }

  /**
   * Returns a new {@code TypeResolver} with type variables in {@code formal} mapping to types in

            

Reported by PMD.

The method 'populateTypeMappings' has a Standard Cyclomatic Complexity of 15.
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

The method 'populateTypeMappings(Map, Type, Type)' has an NPath complexity of 768, current threshold is 200
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

The method 'populateTypeMappings' has a Modified Cyclomatic Complexity of 15.
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

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

Line: 143

                      }
        WildcardType toWildcardType = (WildcardType) to;
        Type[] fromUpperBounds = fromWildcardType.getUpperBounds();
        Type[] toUpperBounds = toWildcardType.getUpperBounds();
        Type[] fromLowerBounds = fromWildcardType.getLowerBounds();
        Type[] toLowerBounds = toWildcardType.getLowerBounds();
        checkArgument(
            fromUpperBounds.length == toUpperBounds.length
                && fromLowerBounds.length == toLowerBounds.length,

            

Reported by PMD.

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

Line: 145

                      Type[] fromUpperBounds = fromWildcardType.getUpperBounds();
        Type[] toUpperBounds = toWildcardType.getUpperBounds();
        Type[] fromLowerBounds = fromWildcardType.getLowerBounds();
        Type[] toLowerBounds = toWildcardType.getLowerBounds();
        checkArgument(
            fromUpperBounds.length == toUpperBounds.length
                && fromLowerBounds.length == toLowerBounds.length,
            "Incompatible type: %s vs. %s",
            fromWildcardType,

            

Reported by PMD.

android/guava/src/com/google/common/reflect/ClassPath.java
50 issues
Logger calls should be surrounded by log level guards.
Design

Line: 467

                        return;
        }
      } catch (SecurityException e) {
        logger.warning("Cannot access " + file + ": " + e);
        // TODO(emcmanus): consider whether to log other failure cases too.
        return;
      }
      if (file.isDirectory()) {
        scanDirectory(file, builder);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 542

                      throws IOException {
      File[] files = directory.listFiles();
      if (files == null) {
        logger.warning("Cannot read directory " + directory);
        // IO error, just skip the directory
        return;
      }
      for (File f : files) {
        String name = f.getName();

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 606

                        url = getClassPathEntry(jarFile, path);
        } catch (MalformedURLException e) {
          // Ignore bad entry
          logger.warning("Invalid Class-Path entry: " + path);
          continue;
        }
        if (url.getProtocol().equals("file")) {
          builder.add(toFile(url));
        }

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 661

                        urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
        }
      } catch (MalformedURLException e) {
        logger.log(WARNING, "malformed classpath entry: " + entry, e);
      }
    }
    return urls.build();
  }


            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.reflect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH;
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;

            

Reported by PMD.

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

Line: 160

                 * @since 16.0
   */
  public ImmutableSet<ClassInfo> getAllClasses() {
    return FluentIterable.from(resources).filter(ClassInfo.class).toSet();
  }

  /**
   * Returns all top level classes loadable from the current class path. Note that "top-level-ness"
   * is determined heuristically by class name (see {@link ClassInfo#isTopLevel}).

            

Reported by PMD.

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

Line: 160

                 * @since 16.0
   */
  public ImmutableSet<ClassInfo> getAllClasses() {
    return FluentIterable.from(resources).filter(ClassInfo.class).toSet();
  }

  /**
   * Returns all top level classes loadable from the current class path. Note that "top-level-ness"
   * is determined heuristically by class name (see {@link ClassInfo#isTopLevel}).

            

Reported by PMD.

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

Line: 185

                  checkNotNull(packageName);
    ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
    for (ClassInfo classInfo : getTopLevelClasses()) {
      if (classInfo.getPackageName().equals(packageName)) {
        builder.add(classInfo);
      }
    }
    return builder.build();
  }

            

Reported by PMD.

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

Line: 201

                  String packagePrefix = packageName + '.';
    ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
    for (ClassInfo classInfo : getTopLevelClasses()) {
      if (classInfo.getName().startsWith(packagePrefix)) {
        builder.add(classInfo);
      }
    }
    return builder.build();
  }

            

Reported by PMD.

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

Line: 219

                  private final File file;
    private final String resourceName;

    final ClassLoader loader;

    static ResourceInfo of(File file, String resourceName, ClassLoader loader) {
      if (resourceName.endsWith(CLASS_FILE_NAME_EXTENSION)) {
        return new ClassInfo(file, resourceName, loader);
      } else {

            

Reported by PMD.

guava/src/com/google/common/reflect/TypeResolver.java
50 issues
The class 'TypeResolver' has a Modified Cyclomatic Complexity of 3 (Highest = 15).
Design

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

The class 'TypeResolver' has a Standard Cyclomatic Complexity of 3 (Highest = 15).
Design

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

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

Line: 56

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();

            

Reported by PMD.

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

Line: 58

              @ElementTypesAreNonnullByDefault
public final class TypeResolver {

  private final TypeTable typeTable;

  public TypeResolver() {
    this.typeTable = new TypeTable();
  }


            

Reported by PMD.

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

Line: 91

                 * <capture-of-? extends Object>}, effectively preventing {@code set} from accepting any type.
   */
  static TypeResolver invariantly(Type contextType) {
    Type invariantContext = WildcardCapturer.INSTANCE.capture(contextType);
    return new TypeResolver().where(TypeMappingIntrospector.getTypeMappings(invariantContext));
  }

  /**
   * Returns a new {@code TypeResolver} with type variables in {@code formal} mapping to types in

            

Reported by PMD.

The method 'populateTypeMappings(Map, Type, Type)' has an NPath complexity of 768, current threshold is 200
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

The method 'populateTypeMappings' has a Modified Cyclomatic Complexity of 15.
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

The method 'populateTypeMappings' has a Standard Cyclomatic Complexity of 15.
Design

Line: 125

                  return new TypeResolver(typeTable.where(mappings));
  }

  private static void populateTypeMappings(
      final Map<TypeVariableKey, Type> mappings, final Type from, final Type to) {
    if (from.equals(to)) {
      return;
    }
    new TypeVisitor() {

            

Reported by PMD.

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

Line: 143

                      }
        WildcardType toWildcardType = (WildcardType) to;
        Type[] fromUpperBounds = fromWildcardType.getUpperBounds();
        Type[] toUpperBounds = toWildcardType.getUpperBounds();
        Type[] fromLowerBounds = fromWildcardType.getLowerBounds();
        Type[] toLowerBounds = toWildcardType.getLowerBounds();
        checkArgument(
            fromUpperBounds.length == toUpperBounds.length
                && fromLowerBounds.length == toLowerBounds.length,

            

Reported by PMD.

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

Line: 145

                      Type[] fromUpperBounds = fromWildcardType.getUpperBounds();
        Type[] toUpperBounds = toWildcardType.getUpperBounds();
        Type[] fromLowerBounds = fromWildcardType.getLowerBounds();
        Type[] toLowerBounds = toWildcardType.getLowerBounds();
        checkArgument(
            fromUpperBounds.length == toUpperBounds.length
                && fromLowerBounds.length == toLowerBounds.length,
            "Incompatible type: %s vs. %s",
            fromWildcardType,

            

Reported by PMD.

guava-tests/test/com/google/common/collect/ImmutableMultimapTest.java
50 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: 39

              @GwtCompatible(emulated = true)
public class ImmutableMultimapTest extends TestCase {

  public void testBuilder_withImmutableEntry() {
    ImmutableMultimap<String, Integer> multimap =
        new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build();
    assertEquals(Arrays.asList(1), multimap.get("one"));
  }


            

Reported by PMD.

The String literal 'one' appears 5 times in this file; the first occurrence is on line 41
Error

Line: 41

              
  public void testBuilder_withImmutableEntry() {
    ImmutableMultimap<String, Integer> multimap =
        new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build();
    assertEquals(Arrays.asList(1), multimap.get("one"));
  }

  public void testBuilder_withImmutableEntryAndNullContents() {
    Builder<String, Integer> builder = new Builder<>();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                public void testBuilder_withImmutableEntry() {
    ImmutableMultimap<String, Integer> multimap =
        new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build();
    assertEquals(Arrays.asList(1), multimap.get("one"));
  }

  public void testBuilder_withImmutableEntryAndNullContents() {
    Builder<String, Integer> builder = new Builder<>();
    try {

            

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

                  assertEquals(Arrays.asList(1), multimap.get("one"));
  }

  public void testBuilder_withImmutableEntryAndNullContents() {
    Builder<String, Integer> builder = new Builder<>();
    try {
      builder.put(Maps.immutableEntry("one", (Integer) null));
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 49

                  Builder<String, Integer> builder = new Builder<>();
    try {
      builder.put(Maps.immutableEntry("one", (Integer) null));
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 49

                  Builder<String, Integer> builder = new Builder<>();
    try {
      builder.put(Maps.immutableEntry("one", (Integer) null));
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();

            

Reported by PMD.

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

Line: 50

                  try {
      builder.put(Maps.immutableEntry("one", (Integer) null));
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 50

                  try {
      builder.put(Maps.immutableEntry("one", (Integer) null));
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 54

                  }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();
    } catch (NullPointerException expected) {
    }
  }

  private static class StringHolder {

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 54

                  }
    try {
      builder.put(Maps.immutableEntry((String) null, 1));
      fail();
    } catch (NullPointerException expected) {
    }
  }

  private static class StringHolder {

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/ImmutableSetTest.java
49 issues
This class has too many methods, consider refactoring it.
Design

Line: 52

               * @author Nick Kralevich
 */
@GwtCompatible(emulated = true)
public class ImmutableSetTest extends AbstractImmutableSetTest {

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();


            

Reported by PMD.

JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 54

              @GwtCompatible(emulated = true)
public class ImmutableSetTest extends AbstractImmutableSetTest {

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(new ImmutableSetCopyOfGenerator())

            

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

                  return ImmutableSet.copyOf(elements);
  }

  public void testCreation_allDuplicates() {
    ImmutableSet<String> set = ImmutableSet.copyOf(Lists.newArrayList("a", "a"));
    assertTrue(set instanceof SingletonImmutableSet);
    assertEquals(Lists.newArrayList("a"), Lists.newArrayList(set));
  }


            

Reported by PMD.

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

Line: 198

                  return ImmutableSet.copyOf(elements);
  }

  public void testCreation_allDuplicates() {
    ImmutableSet<String> set = ImmutableSet.copyOf(Lists.newArrayList("a", "a"));
    assertTrue(set instanceof SingletonImmutableSet);
    assertEquals(Lists.newArrayList("a"), Lists.newArrayList(set));
  }


            

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

                  assertEquals(Lists.newArrayList("a"), Lists.newArrayList(set));
  }

  public void testCreation_oneDuplicate() {
    // now we'll get the varargs overload
    ImmutableSet<String> set =
        ImmutableSet.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "a");
    assertEquals(
        Lists.newArrayList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"),

            

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

                      Lists.newArrayList(set));
  }

  public void testCreation_manyDuplicates() {
    // now we'll get the varargs overload
    ImmutableSet<String> set =
        ImmutableSet.of("a", "b", "c", "c", "c", "c", "b", "b", "a", "a", "c", "c", "c", "a");
    assertThat(set).containsExactly("a", "b", "c").inOrder();
  }

            

Reported by PMD.

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

Line: 217

                  // now we'll get the varargs overload
    ImmutableSet<String> set =
        ImmutableSet.of("a", "b", "c", "c", "c", "c", "b", "b", "a", "a", "c", "c", "c", "a");
    assertThat(set).containsExactly("a", "b", "c").inOrder();
  }

  @GwtIncompatible("Builder impl")
  public void testBuilderForceCopy() {
    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();

            

Reported by PMD.

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

Line: 217

                  // now we'll get the varargs overload
    ImmutableSet<String> set =
        ImmutableSet.of("a", "b", "c", "c", "c", "c", "b", "b", "a", "a", "c", "c", "c", "a");
    assertThat(set).containsExactly("a", "b", "c").inOrder();
  }

  @GwtIncompatible("Builder impl")
  public void testBuilderForceCopy() {
    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();

            

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

                  assertThat(set).containsExactly("a", "b", "c").inOrder();
  }

  @GwtIncompatible("Builder impl")
  public void testBuilderForceCopy() {
    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
    builder.add(-1);
    Object[] prevArray = null;
    for (int i = 0; i < 10; i++) {

            

Reported by PMD.

Avoid unused local variables such as 'unused'.
Design

Line: 229

                    builder.add(i);
      assertNotSame(builder.contents, prevArray);
      prevArray = builder.contents;
      ImmutableSet<Integer> unused = builder.build();
    }
  }

  @GwtIncompatible("Builder impl")
  public void testPresizedBuilderDedups() {

            

Reported by PMD.

android/guava/src/com/google/common/collect/HashBiMap.java
49 issues
Avoid reassigning parameters such as 'entry'
Design

Line: 473

                 * Updates the specified entry to point to the new value: removes the old value from the V-to-K
   * mapping and puts the new one in. The entry does not move in the insertion order of the bimap.
   */
  private void replaceValueInEntry(int entry, @ParametricNullness V newValue, boolean force) {
    checkArgument(entry != ABSENT);
    int newValueHash = Hashing.smearedHash(newValue);
    int newValueIndex = findEntryByValue(newValue, newValueHash);
    if (newValueIndex != ABSENT) {
      if (force) {

            

Reported by PMD.

Avoid reassigning parameters such as 'entry'
Design

Line: 498

                 * mapping and puts the new one in. The entry is moved to the end of the insertion order, or to
   * the position of the new key if it was previously present.
   */
  private void replaceKeyInEntry(int entry, @ParametricNullness K newKey, boolean force) {
    checkArgument(entry != ABSENT);
    int newKeyHash = Hashing.smearedHash(newKey);
    int newKeyIndex = findEntryByKey(newKey, newKeyHash);

    int newPredecessor = lastInInsertionOrder;

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 15

               * the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;
import static com.google.common.collect.NullnessCasts.unsafeNull;


            

Reported by PMD.

The class 'HashBiMap' has a total cyclomatic complexity of 95 (highest 9).
Design

Line: 57

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements BiMap<K, V>, Serializable {

  /** Returns a new, empty {@code HashBiMap} with the default initial capacity (16). */
  public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create() {
    return create(16);

            

Reported by PMD.

Too many fields
Design

Line: 57

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements BiMap<K, V>, Serializable {

  /** Returns a new, empty {@code HashBiMap} with the default initial capacity (16). */
  public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create() {
    return create(16);

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 57

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements BiMap<K, V>, Serializable {

  /** Returns a new, empty {@code HashBiMap} with the default initial capacity (16). */
  public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create() {
    return create(16);

            

Reported by PMD.

Avoid really long classes.
Design

Line: 57

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements BiMap<K, V>, Serializable {

  /** Returns a new, empty {@code HashBiMap} with the default initial capacity (16). */
  public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create() {
    return create(16);

            

Reported by PMD.

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

Line: 58

              @GwtCompatible
@ElementTypesAreNonnullByDefault
public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMap<K, V> implements BiMap<K, V>, Serializable {

  /** Returns a new, empty {@code HashBiMap} with the default initial capacity (16). */
  public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create() {
    return create(16);
  }

            

Reported by PMD.

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

Line: 83

                public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V> create(
      Map<? extends K, ? extends V> map) {
    HashBiMap<K, V> bimap = create(map.size());
    bimap.putAll(map);
    return bimap;
  }

  private static final int ABSENT = -1;
  private static final int ENDPOINT = -2;

            

Reported by PMD.

Field values has the same name as a method
Error

Line: 93

                /** Maps an "entry" to the key of that entry. */
  transient @Nullable K[] keys;
  /** Maps an "entry" to the value of that entry. */
  transient @Nullable V[] values;

  transient int size;
  transient int modCount;
  /** Maps a bucket to the "entry" of its first element. */
  private transient int[] hashTableKToV;

            

Reported by PMD.

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

Line: 89

              @GwtCompatible(serializable = true, emulated = true)
@ElementTypesAreNonnullByDefault
public final class LinkedHashMultimap<K extends @Nullable Object, V extends @Nullable Object>
    extends LinkedHashMultimapGwtSerializationDependencies<K, V> {

  /** Creates a new, empty {@code LinkedHashMultimap} with the default initial capacities. */
  public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create() {
    return new LinkedHashMultimap<>(DEFAULT_KEY_CAPACITY, DEFAULT_VALUE_SET_CAPACITY);

            

Reported by PMD.

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

Line: 122

                 */
  public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap) {
    LinkedHashMultimap<K, V> result = create(multimap.keySet().size(), DEFAULT_VALUE_SET_CAPACITY);
    result.putAll(multimap);
    return result;
  }

  private interface ValueSetLink<K extends @Nullable Object, V extends @Nullable Object> {

            

Reported by PMD.

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

Line: 123

                public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap) {
    LinkedHashMultimap<K, V> result = create(multimap.keySet().size(), DEFAULT_VALUE_SET_CAPACITY);
    result.putAll(multimap);
    return result;
  }

  private interface ValueSetLink<K extends @Nullable Object, V extends @Nullable Object> {
    ValueSetLink<K, V> getPredecessorInValueSet();

            

Reported by PMD.

The class 'ValueEntry' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=8, WMC=11)
Design

Line: 166

                 * whole.
   */
  @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 166

                 * whole.
   */
  @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*

            

Reported by PMD.

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

Line: 168

                @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*
     * The *InValueSet and *InMultimap fields below are null after construction, but we almost
     * always call succeedsIn*() to initialize them immediately thereafter.

            

Reported by PMD.

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

Line: 170

                    extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*
     * The *InValueSet and *InMultimap fields below are null after construction, but we almost
     * always call succeedsIn*() to initialize them immediately thereafter.
     *
     * The exception is the *InValueSet fields of multimapHeaderEntry, which are never set. (That

            

Reported by PMD.

The field initializer for 'valueSetCapacity' is never used (overwritten on line 269)
Design

Line: 262

                private static final int DEFAULT_VALUE_SET_CAPACITY = 2;
  @VisibleForTesting static final double VALUE_SET_LOAD_FACTOR = 1.0;

  @VisibleForTesting transient int valueSetCapacity = DEFAULT_VALUE_SET_CAPACITY;
  private transient ValueEntry<K, V> multimapHeaderEntry;

  private LinkedHashMultimap(int keyCapacity, int valueSetCapacity) {
    super(Platform.<K, Collection<V>>newLinkedHashMapWithExpectedSize(keyCapacity));
    checkNonnegative(valueSetCapacity, "expectedValuesPerKey");

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 325

                 * time the entry is returned by a method call to the collection or its iterator.
   */
  @Override
  public Set<Entry<K, V>> entries() {
    return super.entries();
  }

  /**
   * Returns a view collection of all <i>distinct</i> keys contained in this multimap. Note that the

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 340

                 * <i>adding</i> to the returned set is not possible.
   */
  @Override
  public Set<K> keySet() {
    return super.keySet();
  }

  /**
   * Returns a collection of all values in the multimap. Changes to the returned collection will

            

Reported by PMD.

android/guava/src/com/google/common/math/IntMath.java
48 issues
Using multiple unary operators may be a bug, and/or is confusing.
Error

Line: 107

                static int lessThanBranchFree(int x, int y) {
    // The double negation is optimized away by normal Java, but is necessary for GWT
    // to make sure bit twiddling works as expected.
    return ~~(x - y) >>> (Integer.SIZE - 1);
  }

  /**
   * Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
   *

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 228

                 * @throws IllegalArgumentException if {@code k < 0}
   */
  @GwtIncompatible // failing tests
  public static int pow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'k'
Design

Line: 228

                 * @throws IllegalArgumentException if {@code k < 0}
   */
  @GwtIncompatible // failing tests
  public static int pow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'k'
Design

Line: 491

                 * @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed {@code
   *     int} arithmetic
   */
  public static int checkedPow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 491

                 * @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed {@code
   *     int} arithmetic
   */
  public static int checkedPow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/AtomicDoubleTest.java
48 issues
This class has too many methods, consider refactoring it.
Design

Line: 18

              

/** Unit test for {@link AtomicDouble}. */
public class AtomicDoubleTest extends JSR166TestCase {

  private static final double[] VALUES = {
    Double.NEGATIVE_INFINITY,
    -Double.MAX_VALUE,
    (double) Long.MIN_VALUE,

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 43

              
  /** The notion of equality used by AtomicDouble */
  static boolean bitEquals(double x, double y) {
    return Double.doubleToRawLongBits(x) == Double.doubleToRawLongBits(y);
  }

  static void assertBitEquals(double x, double y) {
    assertEquals(Double.doubleToRawLongBits(x), Double.doubleToRawLongBits(y));
  }

            

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

                }

  /** constructor initializes to given value */
  public void testConstructor() {
    for (double x : VALUES) {
      AtomicDouble a = new AtomicDouble(x);
      assertBitEquals(x, a.get());
    }
  }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

                /** constructor initializes to given value */
  public void testConstructor() {
    for (double x : VALUES) {
      AtomicDouble a = new AtomicDouble(x);
      assertBitEquals(x, a.get());
    }
  }

  /** default constructed initializes to zero */

            

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

                }

  /** default constructed initializes to zero */
  public void testConstructor2() {
    AtomicDouble a = new AtomicDouble();
    assertBitEquals(0.0, a.get());
  }

  /** get returns the last value set */

            

Reported by PMD.

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

Line: 65

                }

  /** get returns the last value set */
  public void testGetSet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.set(x);
      assertBitEquals(x, at.get());

            

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

                }

  /** get returns the last value set */
  public void testGetSet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.set(x);
      assertBitEquals(x, at.get());

            

Reported by PMD.

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

Line: 75

                }

  /** get returns the last value lazySet in same thread */
  public void testGetLazySet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.lazySet(x);
      assertBitEquals(x, at.get());

            

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

                }

  /** get returns the last value lazySet in same thread */
  public void testGetLazySet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.lazySet(x);
      assertBitEquals(x, at.get());

            

Reported by PMD.

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

Line: 85

                }

  /** compareAndSet succeeds in changing value if equal to expected else fails */
  public void testCompareAndSet() {
    double prev = Math.E;
    double unused = Math.E + Math.PI;
    AtomicDouble at = new AtomicDouble(prev);
    for (double x : VALUES) {
      assertBitEquals(prev, at.get());

            

Reported by PMD.