diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 7add376142..afa468cd5a 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,9 @@ /** + * Fix for Lambda expression with one variable + * Bug #1470 + * + * Andreas Dangel 04/2016 + *==================================================================== * Added support for explicit receiver parameters. * Bug #1455 * @@ -1798,7 +1803,9 @@ void PrimaryPrefix() : | "super" {jjtThis.setUsesSuperModifier();} | LOOKAHEAD( "(" ")" "->" ) LambdaExpression() | LOOKAHEAD( "->" ) LambdaExpression() +| LOOKAHEAD( "(" VariableDeclaratorId() ")" "->" ) LambdaExpression() | LOOKAHEAD( "(" VariableDeclaratorId() "," VariableDeclaratorId() ["," VariableDeclaratorId()] ")" "->" ) LambdaExpression() +| LOOKAHEAD( "(" FormalParameter() ")" "->" ) LambdaExpression() | LOOKAHEAD( "(" FormalParameter() "," FormalParameter() ["," FormalParameter() ] ")" "->" ) LambdaExpression() | LOOKAHEAD( LambdaExpression() ) LambdaExpression() | LOOKAHEAD(3) "(" Expression() ")" 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 bd719e7c09..c0cd2ccbbf 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 @@ -90,6 +90,12 @@ public class ParserCornersTest extends ParserTst { + " private void deleteDirectory(String path) {\n" + " LOG.debug(path);\n" + " }\n" + "}"); } + @Test + public void testLambdaBug1470() throws Exception { + String code = IOUtils.toString(ParserCornersTest.class.getResourceAsStream("LambdaBug1470.java"), "UTF-8"); + parseJava18(code); + } + /** * Test for https://sourceforge.net/p/pmd/bugs/1355/ */ diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/LambdaBug1470.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/LambdaBug1470.java new file mode 100644 index 0000000000..93cea72b60 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/LambdaBug1470.java @@ -0,0 +1,27 @@ +package com.sample.test; + +import rx.Observable; +import rx.Subscriber; + +public class pmdTest { + + private boolean stuff; + + public Observable testSuper() { + return Observable.create( + (Subscriber subscriber) -> { + + stuff=true; + }) + .map(authToken -> false); + } + + public Observable testSuper2() { + return Observable.create( + (subscriber) -> { + + stuff=true; + }) + .map(authToken -> false); + } +} diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index d8d3002e19..4677b67db4 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -55,6 +55,7 @@ * [#1455](https://sourceforge.net/p/pmd/bugs/1455/): PMD doesn't handle Java 8 explicit receiver parameters * [#1458](https://sourceforge.net/p/pmd/bugs/1458/): Performance degradation scanning large XML files with XPath custom rules * [#1461](https://sourceforge.net/p/pmd/bugs/1461/): Possible threading issue due to PR#75 + * [#1470](https://sourceforge.net/p/pmd/bugs/1470/): Error with type-bound lambda **API Changes:**