RFR: 8285517: System.getenv() returns unexpected value if environment variable has non ASCII character [v5]
Roger Riggs
rriggs at openjdk.java.net
Fri May 6 20:33:50 UTC 2022
On Fri, 6 May 2022 20:03:35 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> Ichiroh Takiguchi has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8285517: System.getenv() returns unexpected value if environment variable has non ASCII character
>
> src/java.base/share/classes/jdk/internal/util/StaticProperty.java line 77:
>
>> 75: SUN_JNU_ENCODING = getProperty(props, "sun.jnu.encoding");
>> 76: jnuCharset = Charset.forName(SUN_JNU_ENCODING, Charset.defaultCharset());
>> 77: }
>
> I am not sure it is OK to initialize `Charset` here, as `sun_jnu_encoding` is initialized in `System.initPhase1()` and pulling `Charset` there may cause some init order change. I'd only cache the encoding string here.
Note the initialization of `sun.jnu.encoding` in System.java:2142'ish.
This happens before StaticProperty is initialized; at line 2147.
If the `sun.jnu.encoding` is not supported (this is before Providers are enabled)
then it is forced to `UTF-8`.
So it is the case that the encoding is supported by that point.
Note that `Charset.isSupported(...)` does the full lookup in its implementation.
If it is not supported, the system still comes up using UTF-8 and a warning is printed at line 2282.
Comparing the class initialization order may be a useful thing to cross check.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8378
More information about the core-libs-dev
mailing list