Fix #2767
Problem was the stack is empty if the local var declaration is the first node of the compilation unit to be pushed.
This commit is contained in:
@@ -1997,8 +1997,10 @@ void BlockStatement():
|
|||||||
|
|
|
|
||||||
{
|
{
|
||||||
List<Node> annotationsAndChildren = new ArrayList<Node>();
|
List<Node> annotationsAndChildren = new ArrayList<Node>();
|
||||||
while (jjtree.peekNode() instanceof ASTAnnotation) {
|
if (jjtree.nodeArity() > 0) { // peekNode would throw if the stack is empty
|
||||||
annotationsAndChildren.add(jjtree.popNode());
|
while (jjtree.peekNode() instanceof ASTAnnotation) {
|
||||||
|
annotationsAndChildren.add(jjtree.popNode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LocalVariableDeclaration()
|
LocalVariableDeclaration()
|
||||||
|
@@ -177,6 +177,16 @@ public class ParserCornersTest {
|
|||||||
java8.parseResource("GitHubBug207.java");
|
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
|
@Test
|
||||||
public void testBug206() {
|
public void testBug206() {
|
||||||
java8.parse("public @interface Foo {" + "\n"
|
java8.parse("public @interface Foo {" + "\n"
|
||||||
|
Reference in New Issue
Block a user