New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] UnnecessaryFullyQualifiedName false positive for the same name method #1216

Closed
aterai opened this Issue Jun 28, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@aterai

aterai commented Jun 28, 2018

Affects PMD Version:
6.5.0

Rule:
category/java/codestyle.xml/UnnecessaryFullyQualifiedName

Description:
If an import statement using * notation and a method with the same name exists, a false positive is generated for the UnnecessaryFullyQualifiedName rule.

Example:

  • import java.util.stream.*;
    • Arrays.stream(...)
  • import java.time.format.*;
    • LocalDate#format(...)
  • import javax.swing.undo.*;
    • UndoManager#undo()

Code Sample demonstrating the issue:

import java.awt.Component;
import java.awt.Container;
import java.util.Arrays;
import java.util.stream.*;

public final class Test {
  public static Stream<Component> stream(Container parent) {
    return Arrays.stream(parent.getComponents())
      .filter(Container.class::isInstance)
      .map(c -> stream(Container.class.cast(c)))
      .reduce(Stream.of(parent), Stream::concat);
  }
}

Running PMD through: CLI

> pmd.bat -dir C:\tmp\pmd -R category/java/codestyle.xml/UnnecessaryFullyQualifiedName
C:\tmp\pmd\Test.java:8:        Unnecessary use of fully qualified name 'Arrays.stream' due to existing import 'java.util.stream.*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment