pmd: fix #1095 AvoidFinalLocalVariable false positive

This commit is contained in:
Andreas Dangel 2013-08-10 21:19:29 +02:00
parent 9a81bcf7dd
commit 5c92fdd31a
4 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Fixed bug 991: AvoidSynchronizedAtMethodLevel for static methods
Fixed bug 1084: NPE at UselessStringValueOfRule.java:36
Fixed bug 1091: file extension for fortran seems to be wrong in cpdgui tools
Fixed bug 1092: Wrong Attribute "excludemarker" in Ant Task Documentation
Fixed bug 1095: AvoidFinalLocalVariable false positive
Fixed bug 1099: UseArraysAsList false positives
Fixed bug 1102: False positive: shift operator parenthesis
Fixed bug 1104: IdempotentOperation false positive

View File

@ -366,6 +366,7 @@ Avoid using final local variables, turn them into fields.
<value><![CDATA[
//LocalVariableDeclaration[
@Final = 'true'
and not(../../ForStatement)
and
(
(count(VariableDeclarator/VariableInitializer) = 0)

View File

@ -12,7 +12,6 @@ public class ControversialRulesTest extends SimpleAggregatorTst {
@Before
public void setUp() {
addRule(RULESET, "AssignmentInOperand");
addRule(RULESET, "AvoidFinalLocalVariable");
addRule(RULESET, "AvoidLiteralsInIfCondition");
addRule(RULESET, "AvoidPrefixingMethodParameters");
addRule(RULESET, "AvoidUsingNativeCode");

View File

@ -48,6 +48,19 @@ public class A {
final String bar = str.toLowerCase(Locale.getDefault());
final StringBuilder thing = new StringBuilder(128);
}
}
]]></code>
</test-code>
<test-code>
<description>#1095 AvoidFinalLocalVariable false positive</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
public void test() {
final File[] files = new File(".").listFiles();
for (final File f : files) { f.getAbsolutePath(); }
}
}
]]></code>
</test-code>