Affects PMD Version: 7.23.0
Rule: LocalVariableCouldBeFinal
Description: When multiple variables are declared in the same line, and some of them could be final, LocalVariableCouldBeFinal is not raised.
Code Sample demonstrating the issue:
class Foo {
void foo(boolean cond1) {
int i=0, j=1;
if (cond1) {
i = 3;
}
IO.println(i + " " + j);
}
}
Expected outcome:
PMD should report a violation at line 3, but doesn't. This is a false-negative. If I split up the two declarations, there is a violation for j.
PMD does report a OneDeclarationPerLine violation for the above code. I'm aware of PMDs policy to only report one violation for one issue. But PMD also actively encourages users to pick and choose which rules to enable. I find it very surprising that the above code doesn't raise a violation if LocalVariableCouldBeFinal is enabled (and OneDeclarationPerLine is not).
Running PMD through: CLI
Affects PMD Version: 7.23.0
Rule: LocalVariableCouldBeFinal
Description: When multiple variables are declared in the same line, and some of them could be final, LocalVariableCouldBeFinal is not raised.
Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 3, but doesn't. This is a false-negative. If I split up the two declarations, there is a violation for j.
PMD does report a OneDeclarationPerLine violation for the above code. I'm aware of PMDs policy to only report one violation for one issue. But PMD also actively encourages users to pick and choose which rules to enable. I find it very surprising that the above code doesn't raise a violation if LocalVariableCouldBeFinal is enabled (and OneDeclarationPerLine is not).Running PMD through: CLI