RFR: 8311030: ResourceBundle.handleKeySet() is racy

Sergey Tsypanov stsypanov at openjdk.org
Thu Jun 29 21:01:56 UTC 2023


On Thu, 29 Jun 2023 12:23:11 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> Double-checked locking should rely on local variable to avoid racy reads from volatile field.
>
> The role of the local `keySet` seems pretty useless. It doesn't save neither volatile reads nor writes.

@rgiulietti `keySet` is volatile, so providing it has already been initialized, in original code we read from it twice when doing null-check and returning the value. With local variable we read from the field only once, don't we?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14692#issuecomment-1613802472


More information about the core-libs-dev mailing list