views:

121

answers:

3

I have an IntelliJ project with eight modules and roughly 500 KLines of Java. I added a Scala Facet to a module that depends on all the other modules.

When compiling HelloWorld.scala in IntelliJ IDEA 9.0.2:

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello World!")
  }
}

I got the following output in the Messages panel:

Information:Compilation completed with 32 errors and 0 warnings
Information:32 errors
Information:0 warnings
Error:Scalac internal error: class java.lang.reflect.InvocationTargetException [sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method), sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:74)][scala.tools.nsc.typechecker.Typers$class.newTyper(Typers.scala:68), scala.tools.nsc.Global$analyzer$.newTyper(Global.scala:295), scala.tools.nsc.typechecker.Namers$Namer.<init>(Namers.scala:68), scala.tools.nsc.typechecker.Namers$NormalNamer.<init>(Namers.scala:43), scala.tools.nsc.typechecker.Namers$class.newNamer(Namers.scala:44), scala.tools.nsc.Global$analyzer$.newNamer(Global.scala:295), scala.tools.nsc.typechecker.Namers$Namer$$anonfun$enterSyms$1.apply(Namers.scala:258), scala.tools.nsc.typechecker.Namers$Namer$$anonfun$enterSyms$1.apply(Namers.scala:256), scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61), scala.collection.immutable.List.foreach(List.scala:45), scala.tools.nsc.typechecker.Namers$Namer.enterSyms(Namers.scala:256), scala.tools.nsc.typechecker.Namers$Namer.enterSym(Namers.scala:347), scala.tools.nsc.typechecker.Analyzer$namerFactory$$anon$1.apply(Analyzer.scala:39), scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply(Global.scala:276), scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply(Global.scala:276), scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:48), scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:276), scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:252), scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:252), scala.collection.Iterator$class.foreach(Iterator.scala:631), scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:304), scala.tools.nsc.Global$GlobalPhase.run(Global.scala:252), scala.tools.nsc.Global$Run.compileSources(Global.scala:733), scala.tools.nsc.Global$Run.compile(Global.scala:813), scala.tools.nsc.Main$.process(Main.scala:108), scala.tools.nsc.Main$.main(Main.scala:122), scala.tools.nsc.Main.main(Main.scala), sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method), sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:74)]
Error:sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Error:sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Error:sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Error:java.lang.reflect.Method.invoke(Method.java:597)
Error:org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:74)
Error:Caused by java.lang.OutOfMemoryError: Java heap space
Error:scala.tools.nsc.typechecker.Typers$class.newTyper(Typers.scala:68)
Error:scala.tools.nsc.Global$analyzer$.newTyper(Global.scala:295)
Error:scala.tools.nsc.typechecker.Namers$Namer.<init>(Namers.scala:68)
Error:scala.tools.nsc.typechecker.Namers$NormalNamer.<init>(Namers.scala:43)
Error:scala.tools.nsc.typechecker.Namers$class.newNamer(Namers.scala:44)
Error:scala.tools.nsc.Global$analyzer$.newNamer(Global.scala:295)
Error:scala.tools.nsc.typechecker.Namers$Namer$$anonfun$enterSyms$1.apply(Namers.scala:258)
Error:scala.tools.nsc.typechecker.Namers$Namer$$anonfun$enterSyms$1.apply(Namers.scala:256)
Error:scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
Error:scala.collection.immutable.List.foreach(List.scala:45)
Error:scala.tools.nsc.typechecker.Namers$Namer.enterSyms(Namers.scala:256)
Error:scala.tools.nsc.typechecker.Namers$Namer.enterSym(Namers.scala:347)
Error:scala.tools.nsc.typechecker.Analyzer$namerFactory$$anon$1.apply(Analyzer.scala:39)
Error:scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply(Global.scala:276)
Error:scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:48)
Error:scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:276)
Error:scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:252)
Error:scala.collection.Iterator$class.foreach(Iterator.scala:631)
Error:scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:304)
Error:scala.tools.nsc.Global$GlobalPhase.run(Global.scala:252)
Error:scala.tools.nsc.Global$Run.compileSources(Global.scala:733)
Error:scala.tools.nsc.Global$Run.compile(Global.scala:813)
Error:scala.tools.nsc.Main$.process(Main.scala:108)
Error:scala.tools.nsc.Main$.main(Main.scala:122)
Error:scala.tools.nsc.Main.main(Main.scala)

Why is this happening? I can successfully create a new empty project and compile and run this Hello World.

+3  A: 

The problem is that you are running out of memory:

Error:Caused by java.lang.OutOfMemoryError: Java heap space

Thats probably because of the size of your project.
You need to tune the JVM options -Xms and -Xmx for your compiler, so that it is allowed to use more memory.

Philipp
+3  A: 

Did you have a careful look at the stack trace?

Caused by java.lang.OutOfMemoryError: Java heap space

Try setting the max. amount of memory for the JVM higher (on the command line, that's the -Xmx switch, I don't know how to set it for IntelliJ - look it up in the documentation).

Jesper
+2  A: 

This turns out to be a memory problem. Here is the true cause of the compile error with context:

Error:org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:74)
==> Error:Caused by java.lang.OutOfMemoryError: Java heap space <==
Error:scala.tools.nsc.typechecker.Typers$class.newTyper(Typers.scala:68)

File | Settings | Compiler | Scala Compiler the Maximum heap size (MB) is set to 256 by default.

Setting Maximum heap size (MB) to 1024 solved the problem for me.

Alain O'Dea