RFR 8199435 : Unsafe publication of java.util.Properties.map
Doug Lea
dl at cs.oswego.edu
Mon Jun 18 14:21:56 UTC 2018
On 06/18/2018 10:05 AM, Martin Buchholz wrote:
> There's a long history of cheating and setting final fields in
> pseudo-constructors readObject and clone, which is well motivated since
> Java should really support pseudo-constructors in a better way..
> Cheating has used Unsafe or reflection with setAccessible
> (CopyOnWriteArrayList.resetLock()).
>
> Doug - would CopyOnWriteArrayList.clone() be slightly safer if it had a
> releaseFence() ?
>
Or better, lockField.set in resetLock could instead be setRelease.
Except it is using reflection, not VarHandles. So it could be preceded
with VarHandle.releaseFence(), although it is hard to think of a
scenario in which it could matter.
-Doug
More information about the core-libs-dev
mailing list