RFC: Adding ConcurrentModificationException for HashMap.computeIfAbsent(), and JDK-8071667
Paul Sandoz
paul.sandoz at oracle.com
Thu Feb 5 08:46:26 UTC 2015
On Feb 5, 2015, at 1:36 AM, Brent Christian <brent.christian at oracle.com> wrote:
> I prefer this approach of discouraging/preventing side-effects via CME, rather than allowing them. Keep the functions "functional", as it were.
>
> If there are situations where determining the mapping for one key necessitates making additional changes to the Map, that should be coded some other way. IMO, sneaking extra work into computeIfAbsent() is too big a departure from how the method is intended to be used.
>
> Regarding the default methods:
>
> Would we be able to make a "best-effort" detection of comodification by checking for a change in size before and after calling mappingFunction? Or are there other reasons we "cannot do anything" about the default methods?
>
Yes, i suppose we could, of course it would not detect any aliasing when sampling the size.
My inclination is to leave these as is and focus on the most common concrete implementations.
Paul.
More information about the core-libs-dev
mailing list