Affects PMD Version:
6.31.0
Rule:
Description:
I have a static import of all methods in a class but the methods referenced in the code are from its base class. The rule flags the derived class' import as unused despite the compiler recognising the import as valid.
This is unexpected.
Note:
In my opinion, this is fine since it's (strictly) true that the methods do not belong to the specified import. I interpret it as forcing the user the use the correct import. If there are methods available in the derived class and if even one is referenced, then it is used and there is no complation or rule violation for the base class' methods. It's a corner case that probably will occur only in error.
I think the rule must recognise that the parent class' methods are being referenced instead and suggest that the parent class be used instead. It's more of a case of MisusedImport rather than UnusedImport.
Code Sample demonstrating the issue:
class Hello { public static void sayHello() { //... } } class HelloMore extends Hello { // ... } import static HelloMore.*; // flagged as unused public class Test { public static void main(String... args) { sayHello(); } }
Expected outcome:
No violation should be reported.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Referred from: #3130 (comment)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4