You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importstaticjava.lang.Integer.*;
importstaticjava.lang.Long.valueOf;
importstaticjava.lang.Long.*;
publicclassFoo {
publicvoidfoo() {
// the "valueOf" method is both in Integer.* and Long.*// we need an explicit static import to specify one of them, e.g. Long.valueOfvalueOf("123", 10);
// covered by Integer.*inti = parseInt("123");
// covered by Long.*longl = parseLong("123");
}
}
Running PMD through:Other
The text was updated successfully, but these errors were encountered:
adangel
changed the title
[java] FP in UnusedImports for ambiguous on-demand imports
[java] FP in UnusedImports for ambiguous static on-demand imports
Feb 13, 2020
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:
Running PMD through: Other
The text was updated successfully, but these errors were encountered: