pmd: fix #1047 False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1

This commit is contained in:
Andreas Dangel
2012-12-16 12:06:09 +01:00
parent 637006674f
commit 9162917346
3 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,7 @@
???? ??, 2012 - 5.0.2:
Fixed bug 1044: Unknown option: -excludemarker
Fixed bug 1047: False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1
Fixed bug 1048: CommentContent Rule, String Index out of range Exception
November 28, 2012 - 5.0.1:

View File

@ -1,4 +1,8 @@
/**
* Fix wrong consumption of modifiers (e.g. "final") in a for-each loop.
*
* Andreas Dangel 12/2012
* ===================================================================
* Enhance grammar to use LocalVariableDeclaration in a for-each loop.
* This enhances the symbol table to recognize variables declared in such
* a for-each loop.
@ -1914,9 +1918,9 @@ void ForStatement() :
{
"for" "("
(
LOOKAHEAD(Modifiers() Type() <IDENTIFIER> ":")
LOOKAHEAD(LocalVariableDeclaration() ":")
{checkForBadJDK15ForLoopSyntaxArgumentsUsage();}
Modifiers() LocalVariableDeclaration() ":" Expression()
LocalVariableDeclaration() ":" Expression()
|
[ ForInit() ] ";"
[ Expression() ] ";"

View File

@ -146,4 +146,17 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>Bug #1047 False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void bar() {
for ( final String c : strings ) {
System.out.println(c); // use c
}
}
}
]]></code>
</test-code>
</test-data>