diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 6521e0ad27..6dd6dde4cb 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,9 @@ /** + * Allow local classes to carry more than one annotation. + * Bug #208 + * + * Juan Martin Sotuyo Dodero 01/2017 + *==================================================================== * Change lookahead for AnnotationMethodDeclaration in AnnotationTypeMemberDeclaration. * Bug #206 * @@ -1980,7 +1985,7 @@ void BlockStatement(): ClassOrInterfaceDeclaration, but that seems like a hack that could break other things... */ - LOOKAHEAD( [Annotation()] ["final"|"abstract"] "class") [Annotation()] ClassOrInterfaceDeclaration(0) + LOOKAHEAD( (Annotation())* ["final"|"abstract"] "class") (Annotation())* ClassOrInterfaceDeclaration(0) } void LocalVariableDeclaration() : diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index af6d09cf71..1057a107f3 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -152,6 +152,12 @@ public class ParserCornersTest extends ParserTst { parseJava18(code); } + @Test + public void testGitHubBug208ParseError() throws Exception { + String c = IOUtils.toString(this.getClass().getResourceAsStream("GitHubBug208.java")); + parseJava15(c); + } + /** * This triggered bug #1484 UnusedLocalVariable - false positive - * parenthesis diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug208.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug208.java new file mode 100644 index 0000000000..df790a09ff --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug208.java @@ -0,0 +1,11 @@ +public class GitHubBug208 { + public void testMethod() { + @Lazy + @Configuration + class LocalClass { + @Bean Object foo() { + return null; + } + } + } +} \ No newline at end of file diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index eff3cc30e8..12b7192cbb 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -237,6 +237,7 @@ to avoid XSS attacks. * [#185](https://github.com/pmd/pmd/issues/185): \[java] CPD runs into NPE when analyzing Lucene * [#206](https://github.com/pmd/pmd/issues/206): \[java] Parse error on annotation fields with generics * [#207](https://github.com/pmd/pmd/issues/207): \[java] Parse error on method reference with generics + * [#208](https://github.com/pmd/pmd/issues/208): \[java] Parse error with local class with 2 or more annotations * [#213](https://github.com/pmd/pmd/issues/213): \[java] CPD: OutOfMemory when analyzing Lucene * [#1542](https://sourceforge.net/p/pmd/bugs/1542/): \[java] CPD throws an NPE when parsing enums with -ignore-identifiers * [#1545](https://sourceforge.net/p/pmd/bugs/1545/): \[java] Symbol Table fails to resolve inner classes