How to fix the Error: "org.jetbrains.jps.incremental.scala.remote.ServerException java.lang.StackOverflowError" - scala

I'm trying to run the main class in the scala-sbt project. Running the class is resulting in stackoverflow Error, StackTrace pasted below.
I am sure this is not a code Issue because for the same project I was able to run sbt package by setting the memory in sbt conf file as described here: https://stackoverflow.com/q/55874883.
I tried to set the params in Intellij> Settings> Scala Compile Server, but it didn't help to overcome Error.
JDK: Profile Default
Jvm maximum heap size, MB: 2024
JVM options: -server -Xmx2G -Xss20m -XX:MaxPermSize=1000m -XX:ReservedCodeCacheSize=1000m
IntelliJ:
IntelliJ IDEA 2019.1 (Community Edition)
Build #IC-191.6183.87, built on March 27, 2019
JRE: 1.8.0_202-release-1483-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Sbt Version: 1.2.8
Scala Version: 2.11.8
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
java.lang.StackOverflowError
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:273)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.noTailTransform(TailCalls.scala:214)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:403)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.noTailTransform(TailCalls.scala:214)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:403)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
redacted...

I've had the same issue with Intellij IDEA Ultimate 2020.1.1.
None of above options worked for me. But with a hint of the above answer, I found there was also different setting for the Scala compiler, after changing it the error stopped.
I increased the size of stack trace of the Scala compiler server: Preferences -> Compiler -> Scala Compiler -> Scala Compiler Server. Then, change the JVM options accordingly (In my case, -server -Xss1024m).

I've had the same issue with Intellij IDEA Community Edition 2019.3.4.
In the end, what worked for me was this solution. Basically, go to Settings -> Build, Execution, Deployment -> Compiler
Then, on "User-local build process VM options" set the stack size to a greater value with -Xss
In my case, I finally managed to run the tests setting it to -Xss2048m
I hope this helps.

Go to Configure → Edit Custom VM Options and add your changes there

If you're able to do sbt package (so you have sufficient heap size and -Xss configured for sbt) but running class still throws java.lang.StackOverflowError try going to
Settings -> Build, Execution, Deployment -> sbt
and tick
sbt shell -> use for: project reload and builds
try those options

Related

Scala not builds on Java 10

while building through Intellij Idea, I got the following message:
Error:scalac: 'jvm-1.10' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.10'
later, after a Java upgrade
Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM:
1.8 Build, Execution, Deployment -> Complier -> Scala Complier -> Scala Compile Server -> JDK: 1.8
in build.gradle
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
Nothing helps!
upd:
this helps: in build.gradle
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
not needed:
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
"Error:scalac: 'jvm-1.10' is not a valid choice for '-target' Error:scalac: bad option: '-target:jvm-1.10'"
In the JDK compatibility notes as mentioned below, it also indicates
that the Java 10 is not fully supporting Scala 2.12.6 JDK 9 & 10
compatibility notes
As you were saying you build this through IntelliJ IDEA, I suspect
you haven't configure your java version (Java 10) or scala version
(2.12.6) inside running configuration project settings.
And also please try out building/compile your application through
commandline in order to check whether you are getting the same error
with that (Otherwise this is just bad configuration in IDEA tht you
need to change)
JDK 9 & 10 compatibility notes (Mentioned in Scala Docs)
JDK 9 & 10 compatibility notes
As of Scala 2.12.6 and 2.11.12, JDK 9 & 10 support is incomplete. Notably, scalac will not enforce the restrictions of the Java Platform Module System, which means that code that typechecks may incur linkage errors at runtime.
JDK 9 & 10 support requires minimum sbt version 1.1.0, or 0.13.17 in the 0.13.x series.
For more information on JDK 9 & 10 compatibility, watch the “Support JDK 9” issue on GitHub.
The same issue can happen with mixed multi-module gradle projects that use java 11 and scala 2.12.10.
In that case, it may help to reconfigure IntelliJ (2019.2) via
Settings > Build, Execution, Deployment > Scala Compiler
by removing the targets defined in Additional compiler options for the affected scala modules.
I stumbled over this issue when having the same problem with Java 11. The reconfiguration comment of Roland Ewald solved the problem. It is important to mention, that this reconfiguration has to be made for all modules of the project (at least for me this was necessary) as well as that IntelliJ sometimes hides parts of the Additional compiler options, so be sure to click on expand even if they seem empty or correct.

Scala compiler other than 2.12 not working in Eclipse

I just set up a Scala project in Eclipse (Oxygen 4.7.3a, on Ubuntu 18.04) with the Scala-IDE plugin (4.7.0.v-2_12-201709291352-71a28d0) with a simple HelloWorld object. If I set "Properties -> Scala Compiler" to 2.12 everything works as expected: the project compiles and runs. But if I choose any other version (for instance, "Latest 2.10 bundle (dynamic)" I get prompted to do a full rebuild (as expected) but when I go to "Project -> Build" nothing happens. If I have errors in my code, the editor underlines them, but they won't show in "Problems". If I try to run it I get a class not found error.
I get the feeling that it is not actually compiling. Any ideas on what I need to configure differently?
I finally solved it by removing openjdk-11 and installing openjdk-8. After doing that and reinstalling Eclipse and Scala-IDE everything works fine.
It would have been helpful having some feedback from Eclipse regarding what was not working. I figured it out because I tried to build with SBT and the error lead to this SO question: Failed to initialize compiler: object java.lang.Object in compiler mirror not found
I tried the update-alternatives option (also changing the Java path in eclipse.ini) but then I got the "object java.lang.Object in compiler mirror not found" error in Eclipse problems. Since I didn't need openjdk-11 anyway I simply switched to openjdk-8.

Scala: IntelliJ highlights correct code in red

One fine day IntelliJ started highlighting my working Scala code in red. While following commands run without a hitch, IntelliJ thinks that code is full of errors an missing a lot of dependencies.
sbt clean
sbt reload
sbt update
sbt compile
sbt assembly
It reports a lot of Cannot resolve symbols in imports, classes and method-calls on objects like the following. Moreover, it thinks a lot of imports are unused (for the symbols that it can't find)
Interestingly, all this is happening in only one of my projects (that contains two submodules inside parent module), while other Scala projects (including those containing submodules) are working fine.
Things that I've tried without luck:
Delete (rm -rf) build-related directories like .idea, target, ~/.ivy2/caches
Invalidate Caches / Restart...
Update IntelliJ IDEA and Scala plugin to latest versions
Close and re-import the project, quit IntelliJ, reboot the PC (!)
I'm using:
IntelliJ IDEA 2017.3.2 (Community Edition)
Build #IC-173.4127.27, built on December 25, 2017
JRE: 1.8.0_152-release-1024-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.2
My project configurations are:
Scala v2.11.11
SBT v1.0.3
Once again, I'd like to remind that my Scala code is completely functional and that I'm able to run the JAR generated by sbt assembly elsewhere without an issue.
This solution worked for me: Why does intellij IDEA highlight build.sbt?
Go to the menu: File > Invalidate Caches/Restart
Such things happen when project SDK is not set. Also make sure that you have Add Framework Support -> Scala enabled.

Error importing SBT project in IntelliJ / no src folder appears

I'm new to working with both IntelliJ and Scala, so I've been trying to set up a basic HelloWorld project using it. However once I try to load the project I'm met with two problems
I get an error saying there was an "Error while importing SBT project"
No 'src' folder appears on the project tree
I've seen similar problems here and here, but I still can't get the project to load properly.
For some reason this site doesn't let you post an image until you have 10 reputation, so here is a link to the error message I'm receiving http://i.imgur.com/vDZB6SA.png.
From the looks of it, it seems like it's unable to download the necessary dependencies, however I was able to download the scala plugin earlier, so I can't see why there would be a problem now.
I tried following the advice here on updating the proxy settings, but that doesn't work either.
Has anyone encountered a similar problem? I'm really stuck here on how to proceed.
EDIT 1:
Details on IntelliJ
IntelliJ IDEA 2016.2.3
Build #IC-162.1812.17, built on August 30, 2016
JRE: 1.8.0_65-b17 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Setting up the proejct:
I just followed an example and went to New Project > Scala > SBT > name project and finish. Then once it loads I get the error displayed in the picture above. The SBT version is 0.13.8 and the Scala version is 2.11.8

Trying to install SBT-0.13.8 for Windows 7 installs SBT version 0.12.4

I have (multiple times) tried to install SBT-0.13.8 from the SBT download page via the SBT-0.13.8-MSI button and I always end up getting an SBT version which shows the following output
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\Users\Tina\Desktop\example\project\project
error: error while loading CharSequence, class file 'C:\Program Files\Java\jre1.
8.0_20\lib\rt.jar(java/lang/CharSequence.class)' is broken (bad constant pool tag 15 at byte 1470)
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? i
[warn] Ignoring load failure: no project loaded.
> about
[info] This is sbt 0.12.4
[info] No project is currently loaded
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
SBT produces an error message and (!) shows itself as version 0.12.4.!!!
I really made sure that I have no other version of SBT installed and I even made a reboot before re-installing it but nothing changed. SBT files have a creation date of March, 21, 2015. This seems to be the newest version but why does this version show up as 0.12.4 and does not work with JDK1.8?
Looks like the directory you're in is wrong, you want to launch sbt from C:\Users\Tina\Desktop\example\project not C:\Users\Tina\Desktop\example\project\project (note 1 project less).
The second problem you're having is you're trying to use sbt 0.12.4 with Java 8. sbt 0.12.4 uses (as can be seen from the output) Scala 2.9.2 which doesn't work with Java 8. I would recommend migrating to sbt 0.13.8, but if not you could always downgrade to Java 7.
Edit after comments below
The progfun Coursera course download is still configured with sbt
0.12.4 which you're having trouble building because you are using Java 8.
I had a quick go at trying to see if upgrading the project to 0.13.8 would work (FYI it involves editing project/build.properties), but then plugins need to be upgraded, then meta-build code needed to be changed because of namespace changes..
Unless you're willing to experiment more and work you're way through the various changes required to use latest sbt and latest Java (which is what I would do if this were for myself), I would recommend as an alternative to:
Downgrade to Java 7
Notify the relevant people involved in running the course that the source material should be updated as it demonstrably does not work on latest, stable Java.
If your default Java is Java 8 but you want to switch to Java 7 for this out-of-date project setup, you need to create an .sbtopts file at the root of the project containing (note: on separate lines!):
-java-home
C:\Users\Tina\PATH\TO\YOUR\JAVA\HOME