Affects PMD Version: 6.26.0
Description:
Call chains where side-effects occur in arguments are not handled by UnusedAssignment. This is a known issue, described here
|
// For the record this has problems with call chains with side effects, like |
|
// a.foo(a = 2).bar(a = 3); |
It's hard to make this right on master, because of the grammar for expressions. But this is easily fixed in #2794
Code Sample demonstrating the issue:
class Test {
int a() {
int a = 10;
try {
// both method calls may throw, so a = 2 and a = 4 reach after the try,
// but not a = 10
"".substring(a = 2)
.substring(a = 4);
} catch (RuntimeException e) {
}
return a;
}
}
We get
line 3: The initializer for variable 'a' is never used (overwritten on line 7)
line 7: The value assigned to variable 'a' is never used (overwritten on line 8)
but only the first warning is relevant, the other one is a FP
Affects PMD Version: 6.26.0
Description:
Call chains where side-effects occur in arguments are not handled by UnusedAssignment. This is a known issue, described here
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java
Lines 895 to 896 in 59f1fe2
It's hard to make this right on master, because of the grammar for expressions. But this is easily fixed in #2794
Code Sample demonstrating the issue:
We get
but only the first warning is relevant, the other one is a FP