Could not initialize class scala.util.control.NonFatal$

739 views
Skip to first unread message

Hua Jiang

unread,
Oct 21, 2013, 11:59:37 PM10/21/13
to scala-user
Executing the following code reports NoClassDefFoundError's occasionally. And It seem more likely the error is thrown with a higher upperbound. What's going wrong here?

Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: Could not initialize class scala.util.control.NonFatal$
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)


Here is the code:

import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.ArrayBlockingQueue
import ThreadPoolExecutor._
import scala.concurrent._
import scala.concurrent.duration._

implicit val context = ExecutionContext.fromExecutorService(
  new ThreadPoolExecutor(
    5, 5,
    0L, TimeUnit.SECONDS,
    new ArrayBlockingQueue[Runnable](5),
    new CallerRunsPolicy
  )
)

def reduce(a: Future[Long], b: Future[Long]) = {
  a.flatMap(v => b.map(v + _))
}

val upperbound = 100000

val sum = (1 to upperbound).toIterator.map(i => future(i.toLong)).reduce(reduce)

println(Await.result(sum, Duration.Inf))

context.shutdown

Roland Kuhn

unread,
Oct 22, 2013, 5:53:33 AM10/22/13
to Hua Jiang, scala-user
Hi Hua Jiang,

are you sure that you have the same version of scala-library.jar on the classpath when compiling and running your program?

Regards,

Roland

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Jason Zaugg

unread,
Oct 22, 2013, 6:00:58 AM10/22/13
to Roland Kuhn, Hua Jiang, scala-user
I suspect you are getting a stack overflow and an exemption handler is trying to load the class NonFatal to call a method there to decide whether or not to catch it. That class loading itself triggers another SOE. To test the theory, add a reference to NonFatal at the start of your program. 
Reply all
Reply to author
Forward
0 new messages