RFR: 8311030: ResourceBundle.handleKeySet() is racy

Aleksey Shipilev shade at openjdk.org
Thu Jun 29 14:42:54 UTC 2023


On Wed, 28 Jun 2023 11:05:11 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

> Double-checked locking should rely on local variable to avoid racy reads from volatile field.

Yeah, current code looks like a correct volatile-bearing-DCL. `keySet` is safely published already. Introducing local variable gains us nothing here performance-wise. Arguably, readability is worse. So I would avoid doing this change.

We could have explored if we could drop `volatile` from `keySet`, but it does not look safe, given `HashMap` is not safely constructed.

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

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


More information about the core-libs-dev mailing list