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
{{ message }}
Repository navigation
[java] Make UnnecessaryCast check casts in invocation contexts #3219
Is your feature request related to a problem? Please describe. The pmd 7 rule UnnecessaryCast, as reimplemented in #3204 (refs #3218), ignores casts that occur in an invocation context (method arguments). This is because those casts may help select the correct overload. For instance
In this different example, some casts necessary above are now unnecessary.
classMyClass {
voidm(inti) {}
{
m(1); // select m(int)m((int) 1); // unnecessarym((Integer) 1); // unnecessary as the selected overload is anyway `int`
}
}
Describe the solution you'd like Remove the FNs. We could at least easily do this when there is a single potentially applicable method. In other cases, we will have to use the overload resolution facilities of pmd 7.
Activity
Add test cases for #3219
jsotuyod commentedon Apr 2, 2024
PMD will only fail to detect the very last scenario as it stands.
The test cases are already in the code (even if one is disabled)
pmd/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml
Lines 811 to 847 in c9926fb
The rule also includes a TODO to include this:
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java
Lines 124 to 127 in c9926fb