On Thu, 3 Nov 2022 07:41:05 GMT, ExE Boss <d...@openjdk.org> wrote: >> Yeah, the coupling here is rather distasteful. (Otherwise known as a quick >> and dirty hack.) Unfortunately the coupling between HashMap and >> LinkedHashMap is pretty special-purposed for exactly the intended usage >> modes (insertion-order and access-order). It could be improved, but it would >> probably require some refactoring in HashMap, which I didn't want to do >> right now, in order to keep the sequenced stuff separate. > > Another issue are custom `LinkedHashMap` subclasses which override `put(…)` > to do input validation, which would get bypassed by `internalPut(…)`. A > better solution to a private field would be to use [JEP 429: Scoped values]. > > -------------------------------------------------------------------------------- > > That said, using `internalPut(…)` for the case where `getClass() == > LinkedHashMap.class` would probably be fine. > > [JEP 429: Scoped values]: https://openjdk.org/jeps/429
Input validation can't really be done in `put()`, since there are a bunch of other paths such as `computeIfAbsent()` that will insert entries without calling `put()`. I think some judicious refactoring in HashMap to provide better support to LinkedHashMap is called for here. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1014576382