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] UnnecessaryImport false positive for on-demand imports of nested classes #4082

Closed
abyss638 opened this issue Aug 5, 2022 · 0 comments · Fixed by #4083
Closed

[java] UnnecessaryImport false positive for on-demand imports of nested classes #4082

abyss638 opened this issue Aug 5, 2022 · 0 comments · Fixed by #4083
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@abyss638
Copy link

abyss638 commented Aug 5, 2022

Affects PMD Version:
6.48.0 (but works fine in 5.8.1)

Rule:
UnnecessaryImports

Description:
Nested classes (non-static and static) can be imported using on-demand import and static nested classes can be imported with on-demand static import. For both cases PMD will show 'Unused import X.X.X`

Code Sample demonstrating the issue:

package net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package2;

public class C {
    private C() { }

    public class IC {}

    public static class ISC {}
}
package net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package1;

import net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package2.C.*;

public class U {
    IC c;
}
package net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package1;

import static net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package2.C.*;

public class U {
    ISC sc;
}

Expected outcome:
PMD reports a violation Unused net.sourceforge.pmd.lang.java.rule.codestyle.unnecessaryimport.package2.C, but that's wrong. That's a false positive.

Running PMD through:
Ant

@abyss638 abyss638 added the a:false-positive PMD flags a piece of code that is not problematic label Aug 5, 2022
@abyss638 abyss638 changed the title [java] UnnecessaryImport false positive for on-demand imports of nested classses [java] UnnecessaryImport false positive for on-demand imports of nested classes Aug 5, 2022
@adangel adangel added this to the 6.49.0 milestone Aug 24, 2022
adangel added a commit to adangel/pmd that referenced this issue Aug 24, 2022
adangel added a commit to adangel/pmd that referenced this issue Aug 24, 2022
…t-nested-classes

[java] UnnecessaryImport false positive for on-demand imports of nested classes (fix for pmd#4082) pmd#4083
rdesgroppes added a commit to rdesgroppes/rules_jvm that referenced this issue Apr 26, 2023
Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).

Closes bazel-contrib#176.
rdesgroppes added a commit to rdesgroppes/rules_jvm that referenced this issue Apr 26, 2023
closes bazel-contrib#176.

Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).
illicitonion pushed a commit to bazel-contrib/rules_jvm that referenced this issue Apr 26, 2023
closes #176.

Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).
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
2 participants