Aladdin - Scala Bugtracking
[#206] project: compiler priority: low category: bug
submitter assigned to status date submitted
Michel Martin open 2003-10-21 09:33:07.0
subject Nested objects are not thread-safe
code
object O1 {
  object O2 { }
}
what happened
Phase RefCheck expanded this to the following code, which is not thread-safe:
// [[Trees after phase refcheck]]
// Scala source: bug-nested-objects.scala
final class O1() extends scala.Object() {
  final class O2() extends scala.Object() {
    
  };
  private var O2$: O1.O2 = null;
  final def O2: O1.O2 = {
    if (null.$eq$eq(O1.O2$))
      O1.O2$ = new O1.O2()
    else
       {
        
      };
    O1.O2$
  };
  private def O2_$eq(O2: O1.O2): scala.Unit = O1.O2$ = O2
};
final /*object*/ val O1: O1 = new O1();
The problem here is that if two threads access object O2 simultaneously, two instances of it might \ be created, which violates the specification. This problem is known, the aim of this report is just that we do n\ ot forget it.
what expected Thread-safe nested objects.
[back to overview]
Changes of this bug report