Aladdin - Scala Bugtracking
[#1109] project: compiler priority: high category: bug
submitter assigned to status date submitted
Nikolay Sean fixed 2007-05-15 13:02:58.0
subject [contrib #470] WeakReference.toString throws NoSuchElementException (race condition)
code
import scala.ref._
import scala.concurrent._

def test =
    while (true) {
        val r = new WeakReference(List(1, 2))
        r.toString
    }

ops.spawn(test)
ops.spawn(test)
ops.spawn(test)
what happened
Exception in thread "Thread-1" java.util.NoSuchElementException
        at scala.ref.ReferenceWrapper$class.apply(ReferenceWrapper.scala:21)
        at scala.ref.WeakReference.apply(WeakReference.scala:16)
        at scala.ref.Reference$class.toString(Reference.scala:20)
        at scala.ref.WeakReference.toString(WeakReference.scala:16)
        at $scala5cr1p7-haX0R.Main$.test$0((virtual file):11)
        at $scala5cr1p7-haX0R.Main$$anonfun$1.apply((virtual file):15)
        at $scala5cr1p7-haX0R.Main$$anonfun$1.apply((virtual file):15)
        at scala.concurrent.ops$$anon$0.run(ops.scala:28)
Exception in thread "Thread-0" java.util.NoSuchElementException
        at scala.ref.ReferenceWrapper$class.apply(ReferenceWrapper.scala:21)
        at scala.ref.WeakReference.apply(WeakReference.scala:16)
        at scala.ref.Reference$class.toString(Reference.scala:20)
        at scala.ref.WeakReference.toString(WeakReference.scala:16)
        at $scala5cr1p7-haX0R.Main$.test$0((virtual file):11)
        at $scala5cr1p7-haX0R.Main$$anonfun$0.apply((virtual file):14)
        at $scala5cr1p7-haX0R.Main$$anonfun$0.apply((virtual file):14)
        at scala.concurrent.ops$$anon$0.run(ops.scala:28)
what expected nothing printed, because weakReference.toString should not throw, and should return referenced object .toString or <deleted>
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-05-15 13:03:16.0
Nikolay  edited on  2007-05-15 19:53:56.0
Based on discussuion on tha Scala maining list I raised priority to HIGH. Shouldn't we fix this before 2.5-final? Symbol is a compiler suported feature and should be bulet-proof.
Sean  edited on  2007-05-16 13:38:07.0
Note, since we are hitting GC race conditions so often in the old code, even with this bug fix I think internalization is going to be slower than any benefit it provides.