From 455b1c4dedc53230396a05a69b53b55a5a88334e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Wed, 25 Jan 2017 13:11:07 -0300 Subject: [PATCH 1/2] Fix grammar for annotation members - The lookahead (3 tokens) was too small, and without reaching the opening parenthesis assumed it was parsing a method and not a field. - Using a larger lookahead solves the issue. - Fixes #206 --- pmd-java/etc/grammar/Java.jjt | 7 ++++++- .../sourceforge/pmd/lang/java/ast/ParserCornersTest.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index a180a16f4f..0548fdf6d0 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,9 @@ /** + * Change lookahead for AnnotationMethodDeclaration in AnnotationTypeMemberDeclaration. + * Bug #206 + * + * Juan Martin Sotuyo Dodero 01/2017 + *==================================================================== * Allow method references to specify generics. * Bug #207 * @@ -2282,7 +2287,7 @@ void AnnotationTypeMemberDeclaration(): { modifiers = Modifiers() ( - LOOKAHEAD(3) AnnotationMethodDeclaration(modifiers) + LOOKAHEAD(Type() "(") AnnotationMethodDeclaration(modifiers) | ClassOrInterfaceDeclaration(modifiers) | 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 1a025ec9ca..4e151479e7 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 @@ -143,6 +143,15 @@ public class ParserCornersTest extends ParserTst { parseJava18(c); } + @Test + public void testBug206() throws Exception { + String code = "public @interface Foo {" + PMD.EOL + + "static final ThreadLocal> interner =" + PMD.EOL + + " ThreadLocal.withInitial(Interners::newStrongInterner);" + PMD.EOL + + "}"; + parseJava18(code); + } + /** * This triggered bug #1484 UnusedLocalVariable - false positive - parenthesis * @throws Exception From 904223c2e332ab10cacbfc32021b5f8d08e428bc Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 Jan 2017 19:39:39 +0100 Subject: [PATCH 2/2] Update changelog, references #206 --- src/site/markdown/overview/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 9638920dfa..a890b981c0 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -42,6 +42,7 @@ See also [bugfix #1556](https://sourceforge.net/p/pmd/bugs/1556/). ### Fixed Issues * java + * [#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 * [#213](https://github.com/pmd/pmd/issues/213): \[java] CPD: OutOfMemory when analyzing Lucene * java-design