RFR 8199435 : Unsafe publication of java.util.Properties.map
Paul Sandoz
paul.sandoz at oracle.com
Fri Jun 15 18:37:41 UTC 2018
Yes, like that, thanks,
Paul.
> On Jun 15, 2018, at 11:01 AM, Brent Christian <brent.christian at oracle.com> wrote:
>
> On 6/15/18 10:35 AM, Paul Sandoz wrote:
>> I would also publish the map in readHashtable after you have placed in the keys/values.
>
> Like this?
>
> // create CHM of appropriate capacity
> - map = new ConcurrentHashMap<>(elements);
> + ConcurrentHashMap<Object,Object> tmpMap = new ConcurrentHashMap<>(elements);
>
> // Read all the key/value objects
> for (; elements > 0; elements--) {
> Object key = s.readObject();
> Object value = s.readObject();
> - map.put(key, value);
> + tmpMap.put(key, value);
> }
> +
> + UNSAFE.putObjectVolatile(this, MAP_OFFSET, tmpMap);
> }
>
> -B
More information about the core-libs-dev
mailing list