StackOverflowError with Scala on IntelliJ
Asked Answered
K

6

22

I am trying to build a Scala project on IntelliJ using Gradle. I am able to make but compile keeps failing with a stack overflow error.

I looked through other posts with similar issues which suggested increasing heap/stack size (this and this). So far I have tried setting these in JAVA_OPTS and idea64.exe.vmoptions.

-Xss512m -Xms512m -Xmx2048m -XX:ReservedCodeCacheSize=64m -ea

I also tried including -XX:MaxPermSize=2048m which didn't work either (believe it is not supported in Java 8 anyway).

The same code builds for another person with the same configuration. Can anyone please shed some light on what I am missing?

Details:

IntelliJ Ultimate 2016.1
Scala 2.10.3
Java 1.8.0_92

Stack Trace:

java.lang.StackOverflowError
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4522)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4578)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5343)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5360)
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5472)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5480)
    at scala.tools.nsc.transform.Erasure$Eraser.adaptMember(Erasure.scala:642)
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:696)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$96.apply(Typers.scala:4523)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4522)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4578)
Kary answered 3/4, 2017 at 21:2 Comment(1)
This exception is from the compiler process, not the process of IDEA itself. Try to increase -Xss in Settings -> Languages & Frameworks -> Scala Compile Server -> JVM Parameters. Also check that Scala compile server is enabled.Ambi
E
21

I've solved this via:

Preferences -> Build, Execution, Deployment -> Compiler -> Scala Compiler -> Scala Compile Server

And updated JVM options to use a bigger stack size, eg: -Xss8m

Restart for the changes to take effect.

Electrolyze answered 26/2, 2019 at 2:30 Comment(0)
P
20

The exception is from the compiler that IntelliJ employs, hence you need to change the compiler build process' heap size. Go to

File -> Settings -> Build, Execution, Deployment -> Compiler -> Build process 
heap size (Mbytes)

Increase this property to a higher value.

Screenshot showing the settings pane increasing the value to 1024 MBytes

Pericope answered 22/8, 2017 at 6:25 Comment(0)
F
4

Adding -Xss100m in eclipse.ini worked in my case, probably adding similar property in intellijJ may help.

Froissart answered 13/9, 2017 at 5:14 Comment(2)
I have raised similar question on below link, please follow that: #46111344Froissart
100m for stack seems excessive!Shame
W
2

Here is what worked for me:

  • From Windows Powershell, $env:SBT_OPTS="-Xss1024m" and then ran sbt compile

  • Also in IntelliJ v2020.2, following also worked: Settings -> Build, Execution, Deployment -> Build Tools -> SBT -> JVM : VM Parameters : -Xss1024m

Winstonwinstonn answered 5/3, 2021 at 15:46 Comment(0)
D
0

I had same issues and done lots changes in intellij but non of them work.

I removed unused case classes from my code and its working

Discordance answered 23/2, 2021 at 6:13 Comment(0)
G
0

For those poor souls who as me searched all over the internet and could not find a working solution. In my case: updating libraries and Scala to the latest version didn't help; changing changing a stack size using -Xss didn't help; reducing the nesting level of case classes didn't help; restarting Gradle daemon didn't help. I had few case classes with few dozens of fields, some had nested case classes. I found out that it might be related to case classes and removed unnecessary fields in a test case class in a file that couldn't compile and that finally resolved the issue.

Guesswork answered 3/10, 2023 at 4:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.