RFR: 8317246: Cleanup java.net.URLEncoder and URLDecoder use of file.encoding property

Glavo duke at openjdk.org
Thu Sep 28 18:13:11 UTC 2023


On Tue, 19 Sep 2023 14:25:03 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> I'm not sure this is advisable. The `StaticProperty.fileEncoding()` value is fixed during startup to the platform native encoding and can't be overridden like `defaultCharset()` so I think this will have subtle compatibility implications. What gain - if any - do you see from this?

Can `Charset.defaultCharset()` be overridden within the program? It seems impossible.

Although it is lazily initialized, it should be initialized very early in the program (before any user code), so the user cannot actually override it. I also did some testing and `Charset.defaultCharset()` does not change regardless of whether I override `file.encoding` in the main method or the static initializer of the main class.

I think the new code is more straightforward and conforms to the description in the Javadoc (The default charset is used), and does not change the program behavior.

I'm also going to explore annotate `Charset.defaultCharset` with `@Stable`, which might help with JIT inlining.

@cl4es I found that the `defaultCharset` is now being initialized using `StaticProperty.fileEncoding()`, so this PR is just a safe cleanup.

https://github.com/openjdk/jdk/blob/1749ba265b5761dbe2d9d77dac559984b179adf9/src/java.base/share/classes/java/nio/charset/Charset.java#L678

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

PR Comment: https://git.openjdk.org/jdk/pull/15353#issuecomment-1725775582
PR Comment: https://git.openjdk.org/jdk/pull/15353#issuecomment-1729091434


More information about the net-dev mailing list