On Mon, Jun 18, 2018 at 7:21 AM, Doug Lea <d...@cs.oswego.edu> wrote:
> 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. > You mean followed by, not preceded by? try { lockField.set(this, new Object()); + java.lang.invoke.VarHandle.releaseFence(); } catch (IllegalAccessException e) { throw new Error(e); }