Skip to content
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] [7.0-rc1] UnnecessaryImport - Unused static import is being used #4432

Closed
ben-manes opened this issue Mar 26, 2023 · 4 comments · Fixed by #4551
Closed

[java] [7.0-rc1] UnnecessaryImport - Unused static import is being used #4432

ben-manes opened this issue Mar 26, 2023 · 4 comments · Fixed by #4551
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@ben-manes
Copy link

Affects PMD Version:
7.0-rc1 upgrading from 6.55

Rule:
Unused static import

Description:
This static method is imported and being used. It comes from the parent interface on the outer class, but is being used by a static nested class so it must be imported.

Expected outcome:
PMD 7.0-rc1 reports a violation, but that's wrong and not reported by 6.55.

# File Line Problem
1 LocalAsyncLoadingCache.java 19 Unused static import 'com.github.benmanes.caffeine.cache.LocalAsyncCache.composeResult'

Running PMD through: Gradle
This requires workaround in gradle/gradle#24502

@ben-manes ben-manes added the a:false-positive PMD flags a piece of code that is not problematic label Mar 26, 2023
@ben-manes
Copy link
Author

I tried to suppress at the class and method levels, but that was not honored. The only way to resolve this rule is as a ruleSet.xml exclusion, which is broader than desired.

@oowekyala
Copy link
Member

Thanks for the report. Have you tried using a // NOPMD comment on the line of the violation to suppress it?

@ben-manes
Copy link
Author

Thanks for the tip. I had tried an @SuppressedWarnings("PMD.UnnecessaryImport"). Trying the // NOPMD on the import statement did not work, unfortunately.

@ben-manes
Copy link
Author

Oh sorry, I did the line above the import. Commenting after the import statement works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants