Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - case class with 100 fields (StackOverflowError)

I created scala case class with 100 fields +- , When I'm trying to build the project (with gradle) , I'm getting error:

Cause: java.lang.StackOverflowError
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:698)
    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)

I'm using scala 2.11 , and found that in the past, there was a limitation of 22 fields. but it was fixed.

So why the build is failed? (I tried to increase -Xss20m , but it didn't help)

like image 482
Ben Haim Shani Avatar asked Jan 14 '19 21:01

Ben Haim Shani


1 Answers

What worked in my case was setting -Xss in build.gradle script like this:

compileScala {
    options.forkOptions.jvmArgs += "-Xss4m"
}

Then I am able to compile app with case class having 100+ fields using scala 2.11.12. All the other settings (in IntelliJ Idea menus) were not effective.

like image 121
bazinac Avatar answered Oct 28 '22 13:10

bazinac