On Fri, 8 Jan 2021 18:58:03 GMT, Peter Levart <plev...@openjdk.org> wrote:
>> So, are you saying the solution where I kept the fields volatile and >> initialized them with `Map.of()` is safe? If so, that'd be good news; I'm >> inclined these days to write as much null-free code as possible :-) > > Yes, the pre-initialized fields to Map.of() are safe regardless of whether > they are volatile or not (so I would keep them non-volatile to optimize > fast-path). Because the BiClassValues instance is published safely to other > threads via ClassValue and because you never assign null to the fields later > on. Alright, I made a new hybrid of non-volatile fields and never null fields. Hopefully we're getting to the ideal. Again, I really appreciate all the advice and direction you provided here. ------------- PR: https://git.openjdk.java.net/jdk/pull/1918