Merge branch 'pr-2770' into master
[java] Fix #2767, PMD cannot parse a local var with final in instance initializer #2770
This commit is contained in:
@ -20,6 +20,7 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#2708](https://github.com/pmd/pmd/issues/2708): \[java] False positive FinalFieldCouldBeStatic when using lombok Builder.Default
|
||||
* [#2738](https://github.com/pmd/pmd/issues/2738): \[java] Custom rule with @ExhaustiveEnumSwitch throws NPE
|
||||
* [#2756](https://github.com/pmd/pmd/issues/2756): \[java] TypeTestUtil fails with NPE for anonymous class
|
||||
* [#2767](https://github.com/pmd/pmd/issues/2767): \[java] IndexOutOfBoundsException when parsing an initializer BlockStatement
|
||||
|
||||
|
||||
### API Changes
|
||||
|
@ -1997,8 +1997,10 @@ void BlockStatement():
|
||||
|
|
||||
{
|
||||
List<Node> annotationsAndChildren = new ArrayList<Node>();
|
||||
while (jjtree.peekNode() instanceof ASTAnnotation) {
|
||||
annotationsAndChildren.add(jjtree.popNode());
|
||||
if (jjtree.nodeArity() > 0) { // peekNode would throw if the stack is empty
|
||||
while (jjtree.peekNode() instanceof ASTAnnotation) {
|
||||
annotationsAndChildren.add(jjtree.popNode());
|
||||
}
|
||||
}
|
||||
}
|
||||
LocalVariableDeclaration()
|
||||
|
@ -177,6 +177,16 @@ public class ParserCornersTest {
|
||||
java8.parseResource("GitHubBug207.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitHubBug2767() {
|
||||
// PMD fails to parse an initializer block.
|
||||
// PMD 6.26.0 parses this code just fine.
|
||||
java.withDefaultVersion("15-preview")
|
||||
.parse("class Foo {\n"
|
||||
+ " {final int I;}\n"
|
||||
+ "}\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug206() {
|
||||
java8.parse("public @interface Foo {" + "\n"
|
||||
|
Reference in New Issue
Block a user