JDK-8266075 : System property for the native character encoding name
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 17
  • Submitted: 2021-04-27
  • Updated: 2021-05-04
  • Resolved: 2021-05-04
Related Reports
CSR :  
Description
Summary
-------

The system property `native.encoding` provides the underlying host environment's character encoding name.

Problem
-------

[JEP 400][1] intends to switch the default Charset to `UTF-8`. Once JEP 400 has been introduced, `java.nio.charset.Charset#defaultCharset()` would always return `UTF-8` as the `Charset` used in 1-arg `InputStreamReader`/`OutputStreamWriter` constructors. Applications that relied on the method to return the encoding of the host environment will have no migration path without it.

Solution
--------

To encourage apps for smooth migration, provide the character encoding name of the host environment with a new system property `native.encoding`. The value of the system property will be equivalent to the existing `file.encoding` value (becomes public with JEP400, fixed to `UTF-8`), however, setting the value of this new system property, either via the command line or with `System.setProperty()`, will have no effect.

Specification
-------------

Append the following row in the chart listing the system properties in `java.lang.System#getProperties()` method.

     * <tr><th scope="row">{@systemProperty native.encoding}</th>
     *     <td>Character encoding name derived from the host environment and/or
     *     the user's settings. Setting this system property has no effect.</td></tr>


  [1]: https://openjdk.java.net/jeps/400
Comments
I see a release note is already planned. Moving to Approved.
04-05-2021

I think this CSR is okay. We converged on a system property out of concern that an API method for the native encoding would be confusing for many developers. The proposed doesn't preclude re-visiting this in the future. On naming, we converging on "native.encoding" to be consistent with "file.encoding".
29-04-2021