Ben Haim Shani
Ben Haim Shani

Reputation: 265

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)

Upvotes: 7

Views: 840

Answers (1)

bazinac
bazinac

Reputation: 668

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.

Upvotes: 4

Related Questions