New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inner objects inside a class are not singletons #1591
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1591?orig=1
|
@hubertp said: |
@hubertp said: |
Martin Kneissl (mkneissl) said: 2.9.0-1 looks ok. |
Martin Kneissl (mkneissl) said: |
It is possible to create several instances of the same inner object in a multithreaded context which may cause inconsistent singleton access.
This is best illustrated on the sample below.
--- Scala ---
--- javap -private -c -l --
If you look at the bytecode generated by the compiler, the unique() method initializes a private field named "unique$$module" to a reference to a new instance of type "!InnerObjectTest$$unique$$" but there is no synchronization - if several threads access the 'unique()' method concurrently, there is a small chance that they get different objects.
Object access/initialization code should be the same as lazy val access/initialization code
The text was updated successfully, but these errors were encountered: