RFR: 8302603: Use Set.of in java.nio.charset.Charset [v2]
Glavo
duke at openjdk.org
Mon Feb 20 17:56:55 UTC 2023
On Thu, 16 Feb 2023 08:03:21 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Glavo has updated the pull request incrementally with one additional commit since the last revision:
>>
>> update
>
> src/java.base/share/classes/java/nio/charset/Charset.java line 717:
>
>> 715: public final Set<String> aliases() {
>> 716: if (aliasSet == null)
>> 717: aliasSet = Set.of(aliases);
>
> Given that this is racy then it might be better to use a local and avoid someone reading this code puzzling over whether it can return null, e.g.
>
> Set<String> aliasSet = this.aliasSet;
> if (aliasSet == null) {
> this.aliasSet = aliasSet = Set.of(aliases);
> }
>
> You can also drop explicitly initialising it null at line 670.
I have updated the code.
-------------
PR: https://git.openjdk.org/jdk/pull/12570
More information about the nio-dev
mailing list