question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.ArrayIndexOutOfBoundsException during parsing

See original GitHub issue

Hi! I tried to parse a very simple file: class Sample (private val propertyA: String)

using the code from example

fun main() {
    val source = AstSource.File(
        "src/jvmMain/kotlin/sample/Sample.kt"
    )
    val kotlinFile = KotlinGrammarAntlrKotlinParser.parseKotlinFile(source)
    kotlinFile.summary()
        .onSuccess { astList ->
            astList.forEach(Ast::print)
        }.onFailure { errors ->
            errors.forEach(::println)
        }
}

And got such error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 170
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinAstParserImpl.toAstTerminal(AntlrKotlinAstParserImpl.kt:27)
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinAstParserImpl.parse(AntlrKotlinAstParserImpl.kt:82)
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinAstParserImpl.parse(AntlrKotlinAstParserImpl.kt:75)
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinAstParserImplKt.antlrKotlinParser(AntlrKotlinAstParserImpl.kt:138)
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinAstParserImplKt.antlrKotlinParser(AntlrKotlinAstParserImpl.kt:98)
	at kotlinx.ast.parser.antlr.kotlin.AntlrKotlinParser.parse(AntlrKotlinParser.kt:20)
	at kotlinx.ast.grammar.kotlin.common.KotlinGrammarParser$DefaultImpls.parseKotlinFile(KotlinGrammarParser.kt:9)
	at kotlinx.ast.grammar.kotlin.target.antlr.kotlin.KotlinGrammarAntlrKotlinParser.parseKotlinFile(KotlinGrammarAntlrKotlinParser.kt:10)
	at sample.MainKt.main(Main.kt:14)
	at sample.MainKt.main(Main.kt)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
driekscommented, Mar 24, 2020

Hi @VitaSokolova, sorry for the late answer. The build of antlr-kotlin was broken, the version was missing so that the default version was added to gradle metadata. That caused the build of kotlinx.ast to fail. I fixed the kotlinx.ast build here: https://github.com/drieks/antlr-kotlin/commit/b09d76328f7d8c38417174d5621bbdfb52b6405e and the build of kotlinx.ast here: https://github.com/kotlinx/ast/commit/5db757217c18432c65533b943ef36aba650639cc

When you replace this line:

api 'com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin:master'

with:

api 'com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin:5db757217c'

your project should work now.

0reactions
driekscommented, Mar 30, 2020

Hi @VitaSokolova,

your project works fine for me when running in Intellij Idea.

I added a “shadow jar” task to gradle: https://github.com/VitaSokolova/ImpactAnalysisProject/pull/1 (A shadow jar contains all dependencies required to run program)

I also added this to gradle (I don’t know why it is required, it is releated to gradle metadata and should normally be automatically included):

jvmMain {
            dependencies {
                api 'com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin-jvm:5db757217c'
            }
        }

You can now run “gradle clean buildJar” from the command line, or by using the “gradle” tab in Idea, you can click on “ImpactAnalysisProject / Tasks / other / buildJar”. The jar will be created as build/libs/ImpactAnalysisProject.jar.

Please try to run this jar:

java -jar build/libs/ImpactAnalysisProject.jar

This will create this output for me:

java -jar build/libs/ImpactAnalysisProject.jar
PackageHeader(sample)
importList
KlassDeclaration(class Sample)
  KlassDeclaration(constructor)
    KlassDeclaration(val propertyA String)
      KlassModifier(private, visibilityModifier)

If this does not work, please copy the jar into the root folder of the repository and just commit it, I will look into the jar to find the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.ArrayIndexOutOfBoundsException during parsing · Issue ...
Describe the bug this grammar: module Tijs import IO; layout WS = [\ \t\r\n]* ; import ParseTree; start syntax Stmt = "if" "("...
Read more >
ArrayIndexOutOfBoundsException - when parsing a csv file
You want j < line.length and not <= . If there are 10 elements in an Array then there is not an item...
Read more >
AN ARRAYINDEXOUTOFBOUNDSEXCEPTION MAY BE ...
While the XML parser is handling data via the multiple buffers in which it stores data in, a java.lang.ArrayIndexOutOfBoundsException may be thrown due...
Read more >
3 Tips to solve and Avoid java.lang ... - Javarevisited
The error ArrayIndexOutOfBoundsException: 1 means index 1 is invalid and it's out of bounding i.e. more than the length of the array. Since...
Read more >
ERROR: "​java.lang.ArrayIndexOutOfBoundsException
The scenario of this issue: Source Object parameterized & Field Mapping is set to Automatic in Structure/Hierarchy Parser. As the Field mapping ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found