On Tue, 23 Aug 2022 14:31:26 GMT, Сергей Цыпанов <d...@openjdk.org> wrote:

> > I agree that caution is warranted
> 
> But assuming I've reverted the changes that are dubious, how could there be 
> bugs caused by replacement of multiple reads with a single one? I was sure 
> that such replacement improves thread safety as soon as we rid racy reads.

Yes - that's what I was trying to say. I believe reading the volatile only once 
per method is much better for consistency. And I'm not sure I see why the other 
changes were dubious since these methods weren't checking for `null` either?
My point is that if some method in the subclass can set the value to `null` 
asynchronously when some other method in the super class is running then that's 
a NPE time-bomb (and IMO there's a bug lurking if that can happen).

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

PR: https://git.openjdk.org/jdk/pull/9956

Reply via email to