Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

java.lang.ArrayIndexOutOfBoundsException when parsing /* #60

Closed
bishabosha opened this issue Jul 15, 2024 · 7 comments
Closed

java.lang.ArrayIndexOutOfBoundsException when parsing /* #60

bishabosha opened this issue Jul 15, 2024 · 7 comments

Comments

@bishabosha
Copy link

The following source file will cause the parser to hang before emitting java.lang.ArrayIndexOutOfBoundsException

//> using /*

class Foo

errors with

Error: java.lang.ArrayIndexOutOfBoundsException: Index -2147483648 out of bounds for length 14

Workaround: surround with quotes.

Context

I tried out prototyping a directive where one of the values was a raw glob pattern, e.g.

//> using sourceGenerator foo.scala **/*.proto
@bishabosha bishabosha changed the title java.lang.ArrayIndexOutOfBoundsException when parsing */ java.lang.ArrayIndexOutOfBoundsException when parsing /* Jul 15, 2024
@SethTisue
Copy link

reported again today on Discord (one of @bjornregnell's students hit it)

@bjornregnell
Copy link

Yes this was a bit frustrating for the beginner student - I guess it is easy to get bitten by this when you try to find what is wrong in your code by de-commenting stuff here and there with /* and then forgetting to close it with */ which is a kind of plausible error to make for a human... Not easy to know what to do when the build suddenly start to crash -> despair...

@bjornregnell
Copy link

bjornregnell commented Oct 16, 2024

NOTE: it is enough to have a code file with a single /* so it does not require a using-directive to crash...
So this is pretty generally applicable; perhaps increase priority of this bug's labelling?

@bjornregnell
Copy link

bjornregnell commented Oct 16, 2024

Also we were first confused about where it crashed and long suspected the scala compiler which was a bit worrying until we understood that it was the runner.

@bjornregnell
Copy link

bjornregnell commented Oct 16, 2024

Minimal reproduction:

$ scala-cli version
Scala CLI version: 1.5.1
Scala version (default): 3.5.1
$ mkdir empty && cd empty
$ echo "/*" | cat >a.scala
$ scala-cli compile a.scala 
Error: java.lang.ArrayIndexOutOfBoundsException: Index -2147483648 out of bounds for length 3
For more details, please see '/home/bjornr/tmp/empty/.scala-build/stacktraces/1729085559-18129846909220856422.log'
$ head .scala-build/stacktraces/1729085559-18129846909220856422.log 
java.lang.ArrayIndexOutOfBoundsException: Index -2147483648 out of bounds for length 3
  com.virtuslab.using_directives.custom.CustomCharArrayReader.nextChar(CustomCharArrayReader.java:29)
  com.virtuslab.using_directives.custom.Scanner.lambda$skipComment$5(Scanner.java:298)
  com.virtuslab.using_directives.custom.Scanner.skipComment(Scanner.java:308)
  com.virtuslab.using_directives.custom.Scanner.doFetchToken(Scanner.java:187)
  com.virtuslab.using_directives.custom.Scanner.fetchToken(Scanner.java:144)
  com.virtuslab.using_directives.custom.Scanner.nextToken(Scanner.java:98)
  com.virtuslab.using_directives.custom.Scanner.<init>(Scanner.java:27)
  com.virtuslab.using_directives.custom.Parser.<init>(Parser.java:20)
  com.virtuslab.using_directives.UsingDirectivesProcessor.extract(UsingDirectivesProcessor.java:34)

@SethTisue
Copy link

@Gedochao did #67 fix this?

@tgodzik
Copy link
Member

tgodzik commented Dec 20, 2024

Och, that should actually be fixed, we can close it

@tgodzik tgodzik closed this as completed Dec 20, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants