final transient fields serialization
pcj at roundroom.net
Sun Nov 29 21:11:58 UTC 2009
On Nov 10, 2009, at 2:30 AM, Rémi Forax wrote:
> Le 10/11/2009 00:38, David M. Lloyd a écrit :
>> On 11/09/2009 03:30 PM, Pawel Veselov wrote:
>>> It seems that it would be nice if either the final fields were
>>> initialized in a separate block that would be executed on
>>> deserialization, or if readObject() could set them. After all you
>>> have a code block that sets the final fields. Not sure how
>>> feasible that
>>> is, but IMHO, that is a short coming.
>> One possible problem with this is that changing a final field might
>> have some JMM implications (case in point, CopyOnWriteArrayList
>> uses sun.misc.Unsafe#putObjectVolatile() to reinitialize the
>> transient final Lock field, though I don't see anywhere that
>> ObjectInputStream itself takes such precautions; one would think
>> that java.lang.reflect.Field would take care of this for you, but
>> perhaps it does not).
> It does :)
> Chnaging a volatile or a final field by reflection is done with a
Yes for java.lang.reflect.Field, but David's comment reminds me of
which I'm somewhat embarrassed to have neglected after filing...
More information about the core-libs-dev