RFR: 8264032: Improve thread safety of Runtime.version()

Andrey Turbanov github.com+741251+turbanoff at openjdk.java.net
Tue Mar 23 12:25:54 UTC 2021


On Tue, 23 Feb 2021 16:13:21 GMT, liach <github.com+7806504+liach at openjdk.org> wrote:

>This shouldn't be a problem.

What do you mean by "this"? Double racy read?
There are 2 separate reads of fields. First can return non-null value, while second still can get `null`

> src/java.base/share/classes/java/lang/Runtime.java line 824:
> 
>> 822:                     VersionProps.pre(), VersionProps.build(),
>> 823:                     VersionProps.optional());
>> 824:             version = v;
> 
> Can't this just be `return version = new Version(...` than reassigning to a local variable for no good?

It's matter of style. I've seen both styles are acceptable in JDK codebase. I personally prefer placing assigning each variable into separate lines.

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

PR: https://git.openjdk.java.net/jdk/pull/2691


More information about the core-libs-dev mailing list