A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2767 below:

[java] IndexOutOfBoundsException when parsing an initializer BlockStatement · Issue #2767 · pmd/pmd · GitHub

Affects PMD Version: 6.27.0, also tested with the current 6.28.0-SNAPSHOT

Description:
PMD fails to parse an initializer block.
PMD 6.26.0 parses this code just fine.

Exception Stacktrace:

java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.get(ArrayList.java:458)
	at net.sourceforge.pmd.lang.java.ast.JJTJavaParserState.peekNode(JJTJavaParserState.java:60)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.BlockStatement(JavaParser.java:5379)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Block(JavaParser.java:5329)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Initializer(JavaParser.java:2491)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1788)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1755)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:880)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:782)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:502)
	at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:121)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:185)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:107)
	... 12 common frames omitted

Code Sample demonstrating the issue:

class Foo {
    {final int I;}
}

Steps to reproduce:

The problem occurred in our test-cases for our custom PMD rules, the snipped above is the shortest, that still triggers the exception.

This PMD test-case triggers the exception as well:

    <test-code>
        <description>bug report</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
            class Foo {
                {final int I;}
            }
        ]]></code>
    </test-code>

Running PMD through: Other


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4