Merge branch 'master' into pmd/7.0.x
This commit is contained in:
@ -40,6 +40,7 @@ AbstractTokenizer and the custom tokenizers of Fortran, Perl and Ruby are deprec
|
|||||||
* [#2756](https://github.com/pmd/pmd/issues/2756): \[java] TypeTestUtil fails with NPE for anonymous class
|
* [#2756](https://github.com/pmd/pmd/issues/2756): \[java] TypeTestUtil fails with NPE for anonymous class
|
||||||
* [#2759](https://github.com/pmd/pmd/issues/2759): \[java] False positive in UnusedAssignment
|
* [#2759](https://github.com/pmd/pmd/issues/2759): \[java] False positive in UnusedAssignment
|
||||||
* [#2767](https://github.com/pmd/pmd/issues/2767): \[java] IndexOutOfBoundsException when parsing an initializer BlockStatement
|
* [#2767](https://github.com/pmd/pmd/issues/2767): \[java] IndexOutOfBoundsException when parsing an initializer BlockStatement
|
||||||
|
* [#2783](https://github.com/pmd/pmd/issues/2783): \[java] Error while parsing with lambda of custom interface
|
||||||
|
|
||||||
|
|
||||||
### API Changes
|
### API Changes
|
||||||
|
@ -1492,11 +1492,23 @@ void UnaryExpressionNotPlusMinus() #UnaryExpressionNotPlusMinus((jjtn000.getImag
|
|||||||
* meaning we can't be explicit as to what can be casted depending on the cast type (primitive or otherwise)
|
* meaning we can't be explicit as to what can be casted depending on the cast type (primitive or otherwise)
|
||||||
*/
|
*/
|
||||||
| LOOKAHEAD("(" (Annotation())* PrimitiveType() ")") CastExpression()
|
| LOOKAHEAD("(" (Annotation())* PrimitiveType() ")") CastExpression()
|
||||||
| LOOKAHEAD("(" (Annotation())* Type() ( "&" ReferenceType() )* ")" UnaryExpressionNotPlusMinus()) CastExpression()
|
| LOOKAHEAD("(" (Annotation())* Type() ( "&" ReferenceType() )* ")" UnaryExprNotPmStart()) CastExpression()
|
||||||
| PostfixExpression()
|
| PostfixExpression() // this may be a parenthesized expr, which is why we have lookaheads
|
||||||
| SwitchExpression()
|
| SwitchExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void UnaryExprNotPmStart() #void:
|
||||||
|
{}
|
||||||
|
{
|
||||||
|
// Condensed FIRST set of UnaryExpressionNotPlusMinus
|
||||||
|
// Avoid looking ahead for a whole UnaryExpressionNotPlusMinus, but just for a token
|
||||||
|
|
||||||
|
"~" | "!" | "(" | "switch" | "new" | "this" | "super" | Literal() | "@"
|
||||||
|
| <IDENTIFIER>
|
||||||
|
| "void" | PrimitiveType()
|
||||||
|
}
|
||||||
|
|
||||||
void PostfixExpression() #PostfixExpression((jjtn000.getImage() != null)):
|
void PostfixExpression() #PostfixExpression((jjtn000.getImage() != null)):
|
||||||
{}
|
{}
|
||||||
{
|
{
|
||||||
|
@ -172,6 +172,11 @@ public class ParserCornersTest {
|
|||||||
java8.parseResource("GitHubBug207.java");
|
java8.parseResource("GitHubBug207.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLambda2783() {
|
||||||
|
java8.parseResource("LambdaBug2783.java");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGitHubBug2767() {
|
public void testGitHubBug2767() {
|
||||||
// PMD fails to parse an initializer block.
|
// PMD fails to parse an initializer block.
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LambdaBug2783 {
|
||||||
|
// https://github.com/pmd/pmd/issues/2783
|
||||||
|
|
||||||
|
public Spec<String> test() {
|
||||||
|
// cast, block body (the failing case)
|
||||||
|
Spec<String> result = (Spec<String>) (a, b) -> {
|
||||||
|
return a.toArray(String[]::new);
|
||||||
|
};
|
||||||
|
// no cast, block body
|
||||||
|
result = (a, b) -> {
|
||||||
|
return a.toArray(String[]::new);
|
||||||
|
};
|
||||||
|
// cast, expression body
|
||||||
|
result = (Spec<String>) (a, b) -> a.toArray(String[]::new);
|
||||||
|
|
||||||
|
// return position?
|
||||||
|
return (Spec<String>) (a, b) -> {
|
||||||
|
return a.toArray(String[]::new);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Spec<T> {
|
||||||
|
String[] process(List<T> var1, List<?> var2);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user