From 61c0b4ea7f26f6530ecad4ed5b1ae22b8b3d1ffe Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 26 Jan 2013 14:28:29 +0100 Subject: [PATCH] pmd: fixed #1007 Parse Exception with annotation --- pmd/etc/changelog.txt | 1 + pmd/etc/grammar/Java.jjt | 6 +++++- .../sourceforge/pmd/ast/ParserCornerCases.java | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 63622b0f79..b989085a64 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -2,6 +2,7 @@ Fixed bug 878: False positive: UnusedFormalParameter for abstract methods Fixed bug 913: SignatureDeclareThrowsException is raised twice +Fixed bug 1007: Parse Exception with annotation Fixed bug 1012: False positive: Useless parentheses. Fixed bug 1020: Parsing Error Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation diff --git a/pmd/etc/grammar/Java.jjt b/pmd/etc/grammar/Java.jjt index 84d78f4d8e..a63a8f76f2 100644 --- a/pmd/etc/grammar/Java.jjt +++ b/pmd/etc/grammar/Java.jjt @@ -1,4 +1,8 @@ /** + * Fix ForStatement to allow Annotations within the initializer. + * + * Andreas Dangel 01/2013 + * =================================================================== * Fix wrong consumption of modifiers (e.g. "final") in a for-each loop. * * Andreas Dangel 12/2012 @@ -1932,7 +1936,7 @@ void ForStatement() : void ForInit() : {} { - LOOKAHEAD( [ "final" ] Type() ) + LOOKAHEAD( LocalVariableDeclaration() ) LocalVariableDeclaration() | StatementExpressionList() diff --git a/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java b/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java index 433db3b7aa..108a4708f1 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java +++ b/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java @@ -122,4 +122,20 @@ class SimpleBeanUser2 extends SimpleBeanUser { name = "test2"; }}); } -} \ No newline at end of file +} + +/* + * Test case for bug #1007 Parse Exception with annotation + */ +class TestParseAnnototation { + void parse() { + for (@SuppressWarnings("unchecked") int i = 0; i < 10; i++) { + } + for (@SuppressWarnings("unchecked") Iterator it = Fachabteilung.values().iterator(); it.hasNext();) { + } + List l = new ArrayList(); + for (@SuppressWarnings("unchecked") String s : l) { + } + } +} +