Skip to content

[java] Update rule UnnecessaryImport#3718

Merged
oowekyala merged 15 commits into
pmd:pmd/7.0.xfrom
oowekyala:update-UnnecessaryImport
Jan 26, 2022
Merged

[java] Update rule UnnecessaryImport#3718
oowekyala merged 15 commits into
pmd:pmd/7.0.xfrom
oowekyala:update-UnnecessaryImport

Conversation

@oowekyala

@oowekyala oowekyala commented Jan 4, 2022

Copy link
Copy Markdown
Member

Describe the PR

Part of #2701

Related issues

  • Fixes #

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@oowekyala oowekyala added this to the 7.0.0 milestone Jan 4, 2022
@oowekyala oowekyala force-pushed the update-UnnecessaryImport branch from a04a284 to 0871b5a Compare January 4, 2022 23:41
@oowekyala oowekyala changed the title [java] Update unnecessary import [java] Update rule UnnecessaryImport Jan 4, 2022
@ghost

ghost commented Jan 16, 2022

Copy link
Copy Markdown
2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2555 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 49331 violations,
introduces 26246 new violations, 5 new errors and 0 new configuration errors,
removes 148883 violations, 25 errors and 0 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2549 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 48868 violations,
introduces 26246 new violations, 5 new errors and 0 new configuration errors,
removes 148889 violations, 25 errors and 0 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2573 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 48864 violations,
introduces 26353 new violations, 5 new errors and 0 new configuration errors,
removes 148871 violations, 27 errors and 0 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2573 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 48864 violations,
introduces 26353 new violations, 5 new errors and 0 new configuration errors,
removes 148871 violations, 27 errors and 0 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2573 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 48864 violations,
introduces 26353 new violations, 5 new errors and 0 new configuration errors,
removes 148871 violations, 27 errors and 0 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 48833 violations,
introduces 26251 new violations, 5 new errors and 0 new configuration errors,
removes 151342 violations, 27 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@oowekyala oowekyala marked this pull request as ready for review January 16, 2022 14:47
@adangel

adangel commented Jan 20, 2022

Copy link
Copy Markdown
Member

Thanks for updating this rule - it looks good. While looking through the regression tester report, I found some possible false positives:

a) https://github.com/checkstyle/checkstyle/blob/checkstyle-9.1/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeTestStaticImports.java#L20
I think, this is explainable by incomplete classpath: the referenced class "InputIllegalType" is in the same package, but all this source is under "src/test/resources" - so it is not compiled. Maybe it's worth to specially try to compile these additional sources from checkstyle - should be doable in

mvn test-compile -B
by adding some custom "javac" calls... but that's for another PR.

b) https://github.com/checkstyle/checkstyle/blob/checkstyle-9.1/src/test/java/com/puppycrawl/tools/checkstyle/AbstractXmlTestSupport.java#L22
com.google.common.truth.Truth.assertThat is claimed to be unnecessary. But I think it is indeed used at Line 230.
Maybe we have a problem with statically imported methods?
In spring framework, there is a similar case with org.assertj.core.api.Assertions.within.

Unless we have a problem with our classpath, since both methods would come in through a 3rd party library...

c) https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java#L40
Unused import "sun.nio.ch.DevPollArrayWrapper.NUM_POLLFDS".
That's probably due to the fact, that the class DevPollArrayWrapper is not on the classpath. It's from the package "sun.nio", so it's a platform specific implementation... in this case for solaris...

d) https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java#L49
Unused import "java.util.concurrent.Flow.Subscription"
In this case, it should be on the classpath, shouldn't it? I'm not sure at the moment, how we deal with jdk classes - all the types are loaded via AsmSymbolResolver, right? Not sure, if we also have the jdk itself on the auxclasspath....

In this (big) file SubmissionPublisher, the interface "Subscription" is mostly referenced via "Flow.Subscription", but on Line 886 just with "Subscription".

@oowekyala

Copy link
Copy Markdown
Member Author

Thanks for the review! I think I'll add additional logic to be more conservative when an import is unresolved. The rule already handles unresolved type imports gracefully, thanks to the unresolved symbols of the symbol API. I think we should also be more intelligent with unresolved static imports.

@oowekyala

Copy link
Copy Markdown
Member Author

Actually let's do this in a followup PR. I'll investigate the FP (d) you found in this PR.

@oowekyala

Copy link
Copy Markdown
Member Author

@oowekyala

Copy link
Copy Markdown
Member Author

I think the new FP should be fixed with #3748. This PR is ready to merge IMO

@oowekyala oowekyala merged commit c026fa0 into pmd:pmd/7.0.x Jan 26, 2022
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
@oowekyala oowekyala deleted the update-UnnecessaryImport branch May 13, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants