I am trying to define one case class with 1000 fields in scala REPL 2.11.8. The case class definition is like:
case class Step2_Class(
`Response` : String,
`D1` : String,
`D2` : String,
`D3` : String,
`D4` : String,
//......,
`D999` : String,
`D1000` : String)
And the REPL is waiting for response. After about 1 hour, following stack overflow exception is thrown out.
java.lang.StackOverflowError
at scala.reflect.internal.Trees$class.traverseComponents$1(Trees.scala:1294)
at scala.reflect.internal.Trees$class.itraverse(Trees.scala:1330)
at scala.reflect.internal.SymbolTable.itraverse(SymbolTable.scala:16)
at scala.reflect.internal.SymbolTable.itraverse(SymbolTable.scala:16)
at scala.reflect.api.Trees$Traverser.traverse(Trees.scala:2475)
at scala.reflect.internal.Positions$DefaultPosAssigner.traverse(Positions.scala:288)
at scala.reflect.internal.Positions$DefaultPosAssigner.traverse(Positions.scala:282)
at scala.reflect.internal.Trees$class.traverseComponents$1(Trees.scala:1283)
at scala.reflect.internal.Trees$class.itraverse(Trees.scala:1330)
Do you have any ideas? Does scala not support such case? Are there any work-arounds?
It seems that the error is not related to the number of fields.
You said that it breaks after some time. Are you sure that you haven't a recursive function without a return condition? The StackOverFlow infact is a runtime error.
Thrown when a stack overflow occurs because an application recurses too deeply.
If the problem is related to the number of fields it appears at compile time.
While the problem is not related to the number of fields it is a very bad idea to create a code with 1000 parameters, or a class with 1000 fields. As you can imagine there is no real difference between D1 and D15 and D1000, so why don't use an array called D?
Until recently there was a limit of 22 fields in a case class. So it isn't surprising if the compiler (or REPL itself) fails to gracefully handle 1000 fields. You can try to give it more memory (and stack memory in particular) by setting JAVA_OPTS
(-Xss
for stack overflow in particular), e.g.
JAVA_OPTS="$JAVA_OPTS -Xss8M" scala
but you'd have to guess how much, it wouldn't help much with speed (unless it's mostly stuck garbage collecting, which is quite possible), and it could fail with more fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With