[concurrency-interest] File object is not immutable?
forax at univ-mlv.fr
Wed Feb 15 12:14:25 EST 2012
On 02/15/2012 04:00 PM, Ruslan Cheremin wrote:
> I was very surprised to see that field "path" in java.io.File is not
> final. I was treating File object in concurrency area is something
> like String -- fully immutable, and completely thread-safe, even
> data-race safe.
> Am I right supposing that File object is _not_ thread safe by itself
> (as String does), and it is programmer's responsibility to safe
> publish it between threads? Or may be it is some kind of hidden magic,
> which makes File safe, even without explicit final? I mean, there is
> native calls to FileSystem in constructor and deserialization, which
> can create membars implictly...
The javadoc says File is immutable so it's a bug :(
There is no guarantee that the fs object will do a memory barrier.
I think path is not final because of the serialization code but
it should be final and the seralization code should use
reflection or sun.misc.Unsafe.
I've put Alan Bateman in CC because I don't know if java.io.File is
managed by the core team or the nio one.
> Cheremin Ruslan
More information about the Concurrency-interest