RFR 8199435 : Unsafe publication of java.util.Properties.map

Martin Buchholz martinrb at google.com
Mon Jun 18 15:22:21 UTC 2018


On Mon, Jun 18, 2018 at 7:21 AM, Doug Lea <dl at 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);
         }


More information about the core-libs-dev mailing list