|
[#1218] |
project: distribution |
priority: low |
category: bug |
|
submitter |
assigned to |
status |
date submitted |
|
Nikolay |
Lex |
fixed |
2007-07-17 10:27:52.0 |
subject |
[contrib #693] NoClassDefFoundError when running script |
code |
// Tested using 2.5.1-final
// Note that the particular class not found varied as I simplified the example to the following:
// NoClassDefFoundTest8.scala
object Test
{
abstract class Abstract
{
private val content = new scala.collection.mutable.HashMap[Int, String] with scala.collection.mutable.SynchronizedMap[Int, String]
final def apply(): Nothing =
{
throw new ArithmeticException()
}
}
class Concrete extends Abstract
{
}
class MyHolder
{
val data = new Concrete()
}
class MyThread extends Thread
{
override def run(): Unit =
{
new MyHolder().data()
}
}
def main(args: Array[String]): Unit =
{
new MyThread().start()
}
}
Test.main(new Array[String](0))
/*
$ scala -howtorun:script NoClassDefFoundTest8.scala
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: $scalascript/Main$Test$1$Abstract$$anon$0
at $scalascript.Main$Test$1$MyHolder.<init>((virtual file):23)
at $scalascript.Main$Test$1$MyThread.run((virtual file):30)
To see the expected behaviour:-
Comment out the last line
// Test.main(new Array[String](0))
$ scalac NoClassDefFoundTest8.scala
$ scala Test
Exception in thread "Thread-0" java.lang.ArithmeticException
at Test$Abstract.apply(NoClassDefFoundTest8.scala:9)
at Test$MyThread.run(NoClassDefFoundTest8.scala:26)
We can achieve the expected behaviour from a script by instantiating a MyHolder before starting a new thread:-
def main(args: Array[String]): Unit =
{
new MyHolder() // added
new MyThread().start()
}
$ scala -howtorun:script NoClassDefFoundTest8.scala
Exception in thread "Thread-0" java.lang.ArithmeticException
at $scalascript.Main$Test$1$Abstract.apply((virtual file):16)
at $scalascript.Main$Test$1$MyThread.run((virtual file):33)
*/
|
what happened |
Exception in thread "Thread-0" java.lang.NoClassDefFoundError
|
what expected |
Exception in thread "Thread-0" java.lang.ArithmeticException |
[back to overview] |