From 91629173469b84c760c704421e59c6924a1cfd86 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 16 Dec 2012 12:06:09 +0100 Subject: [PATCH] pmd: fix #1047 False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1 --- pmd/etc/changelog.txt | 1 + pmd/etc/grammar/Java.jjt | 8 ++++++-- .../optimizations/xml/LocalVariableCouldBeFinal.xml | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index f8a9fe0eb7..bac7e7c936 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -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: diff --git a/pmd/etc/grammar/Java.jjt b/pmd/etc/grammar/Java.jjt index 8c83f0fa83..84d78f4d8e 100644 --- a/pmd/etc/grammar/Java.jjt +++ b/pmd/etc/grammar/Java.jjt @@ -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() ":") + LOOKAHEAD(LocalVariableDeclaration() ":") {checkForBadJDK15ForLoopSyntaxArgumentsUsage();} - Modifiers() LocalVariableDeclaration() ":" Expression() + LocalVariableDeclaration() ":" Expression() | [ ForInit() ] ";" [ Expression() ] ";" diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/LocalVariableCouldBeFinal.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/LocalVariableCouldBeFinal.xml index 8241bde619..a323f6880d 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/LocalVariableCouldBeFinal.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/LocalVariableCouldBeFinal.xml @@ -146,4 +146,17 @@ public class Foo { } ]]> + + Bug #1047 False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1 + 0 + +