12

I have been facing this error for sometime now. Totally irritated because of this. Tried all the similar solutions seen in stackoverflow and other sites.

I have a 4 separate scala projects. Out of those, I am getting StackOverflow error on compilation of tow projects. These two projects are the biggest ones out of the 4 projects. I am getting this error when I try to build the project in Ubuntu Server machine. I tried increasing the Xmx options in sbt config file, but with no success.

Can anyone please help me to solve this, as I am going mad because of this. If I build the project 10 times, it will get succeeded in 1 or 2 attempts.

What I understood from the error log is that the issue comes with type checking. But, I have no idea where that occurs.

One of the failing projects have over 1000 classes/traits (without including case classes).

Details:

Ubuntu Server(14)
Sbt : 0.13.6 and 0.13.8 tried
Scala Version : 2.11.6
JDK: 1.8

A few lines of the error is pasted below:

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)
    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.typedArg(Typers.scala:3163)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgWithFormal$1(PatternTypers.scala:112)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
    at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:46)
    at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:44)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.runtime.Tuple2Zipped$.map$extension(Tuple2Zipped.scala:44)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgsForFormals(PatternTypers.scala:115)
    at scala.tools.nsc.typechecker.Typers$Typer.typedArgsForFormals(Typers.scala:111)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$handleMonomorphicCall$1(Typers.scala:3469)
    at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3494)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4544)
    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(E
Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80

2 Answers2

4

This has been affecting Scala since 2.11.4 till 2.11.6 afaik. It doesn't appears as fixed on the latest release notes for 2.11.7.

Fortunately following the track on the issue tracker it's a duplicated ticket with an answer here on stack overflow

Without the source code is harder to give more indications but that should definitely be a good pointer to find the issue and apply the proposed solution

Jaime Agudo
  • 8,076
  • 4
  • 30
  • 35
  • I am using a lot of generics, but as mentioned in the ticket, we do not have manifest with Any. I tried all the memory related settings, but with no use. – Yadu Krishnan Jul 15 '15 at 09:01
  • You didn't mention that you haven't manifest. Anyway you can try a) searching for `Manifest` usage in the libraries you might be using, it's likely some of them are using it b) Upgrade your project to Scala 2.11.7 c) Report the bug to scala-lang.org – Jaime Agudo Jul 15 '15 at 09:11
  • Just to be clear, I am using Manifest in some places for json deserialization. For eg: def extractEntity(json: String)(implicit m: Manifest[E]): E = parse(json).extract[E], where E is a trait called as BaseEntity with some common fields(id, isActive etc). Currently, I am using 2.11.6. I will try with 2.11.7 and check if the issue exist. – Yadu Krishnan Jul 15 '15 at 09:17
  • If the `Manifest` usage is within your code I suggest you to replace them with `TypeTags` and `ClassTags` [see this](http://docs.scala-lang.org/overviews/reflection/typetags-manifests.html). As it's gonna be deprecated it's possible that the Scala guys won't fix the bug at all, as I said it doesn't appear on the recent 2.11.7 release notes – Jaime Agudo Jul 15 '15 at 09:30
  • Thanks for the suggestion. Json4s's extract method is expecting Manifest as an implicit parameter. I need to try how to get away without using that method in that case. – Yadu Krishnan Jul 15 '15 at 09:41
  • I tried removing all the implicit Manifest, but the issue remains same :( – Yadu Krishnan Aug 31 '15 at 10:35
0

I tried all the configuration changes, but didn't work in the machine. So I had skipped this for almost a month. Recently, I tried building the project in Jenkins and was getting the same error. Then I upgraded sbt 0.13.8 and added the jvm flag -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx1024M -Xss16M to the jenkins build flag. And so far, all the compilations have been successful. I remember adding the jvm flag to sbt config file, but was getting the same error. But now, it is working fine in jenkins after adding that flag.

Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80