Affects PMD Version: 6.21
Rule: UnusedImport
Description:
When multiple static on-demand imports match the same method in the code, a regular static import must be used to specify the actual method to use.
The rule may flag the static import as unused, even though it is required.
Also, the rule currently behaves differently, depending on the order of the statements.
In the example below, the "valueOf" method is matched to the "Integer.*" import, which leaves the the "Long.valueOf" import unmatched.
If the "valueOf" method is moved to the bottom of the method, all imports are matched and nothing is flagged.
Code Sample demonstrating the issue:
import static java.lang.Integer.*; import static java.lang.Long.valueOf; import static java.lang.Long.*; public class Foo { public void foo() { // the "valueOf" method is both in Integer.* and Long.* // we need an explicit static import to specify one of them, e.g. Long.valueOf valueOf("123", 10); // covered by Integer.* int i = parseInt("123"); // covered by Long.* long l = parseLong("123"); } }
Running PMD through: Other
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