<i18n dev> RFR: 8316557: Make fields final in 'sun.util' package

Chen Liang liach at openjdk.org
Mon Sep 25 09:50:12 UTC 2023


On Mon, 25 Sep 2023 09:40:00 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

>> src/java.base/share/classes/sun/util/PropertyResourceBundleCharset.java line 71:
>> 
>>> 69:     private final class PropertiesFileDecoder extends CharsetDecoder {
>>> 70: 
>>> 71:         private final CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
>> 
>> Can be static as well.
>
> I'm not sure. Why do you think so? CharsetDecoder is not thread-safe.

UTF8 decoder does not perform any internal state mutation during decoding; in addition, if this field is static final, the decoder's error actions are published when the class is initialized, while publishing in a final field does not guarantee the internal state of the charset is visible to other threads.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15736#discussion_r1335653054


More information about the i18n-dev mailing list