RFR: 8376483: Avoid loading java.nio.charset.StandardCharsets in java.util.zip.ZipCoder

Chen Liang liach at openjdk.org
Tue Jan 27 14:29:33 UTC 2026


On Tue, 27 Jan 2026 10:44:42 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

> Please review this PR which removes a dependency on `java.nio.charset.StandardCharsets` introduced in [JDK-8365703](https://bugs.openjdk.org/browse/JDK-8365703).
> 
> We can use `UTF_8.INSTANCE` here as elsewhere in this class to prevent startup regression loading otherwise unused classes and charsets.
> 
> Verified that running `java -cp hello.jar Hello` observes the following diff in loaded classes when run with this PR:
> 
> 
> < java.nio.charset.StandardCharsets
> < sun.nio.cs.US_ASCII
> < sun.nio.cs.ISO_8859_1
> < sun.nio.cs.UTF_16BE
> < sun.nio.cs.UTF_16LE
> < sun.nio.cs.UTF_16
> < sun.nio.cs.UTF_32BE
> < sun.nio.cs.UTF_32LE
> < sun.nio.cs.UTF_32
> 
> 
> This is a strict refactoring, no tests updated, `noreg-trivial`.

I don't think this is worth it - most user programs will refer to UTF_8 as StandardCharsets.UTF_8, so this doesn't really optimize anything. Also in the ArrayDeque to ArrayList case, ArrayList has other allocation benefits in addition to avoiding ArrayDeque class load. So I personally recommend withdrawing this patch, especially that AOT preimage should be able to capture the linked or even initialized state of StandardCharsets class.

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

PR Comment: https://git.openjdk.org/jdk/pull/29443#issuecomment-3805526018


More information about the core-libs-dev mailing list