RFR: 8359119: There are several opportunities to use Stable Values in j.n.c.Charset

Per Minborg pminborg at openjdk.org
Tue Jun 10 14:17:59 UTC 2025


On Tue, 10 Jun 2025 14:09:03 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> Fields and methods can better leverage the Stable Value API compared to using DCL and holder classes. There are also some fields that can be marked `@Stable`.
> 
> This PR passes tier1, tier2, and tier3 tests on multiple platforms.

src/java.base/share/classes/java/nio/charset/Charset.java line 353:

> 351:     private static Iterator<CharsetProvider> providers() {
> 352:         return new Iterator<>() {
> 353:                 final ClassLoader cl = ClassLoader.getSystemClassLoader();

Drive by fix. We forgot to declare these fields `final`.

src/java.base/share/classes/java/nio/charset/Charset.java line 377:

> 375:                 }
> 376: 
> 377:                 public void remove() {

`remove()` is specified to throw UOE unless overridden. So, removing this redundant code.

src/java.base/share/classes/java/nio/charset/Charset.java line 683:

> 681:         }
> 682:         this.name = canonicalName;
> 683:         this.aliasSet = Set.of(as);

Creating an unmodifiable set is probably more efficient than storing an array and then lazily creating a set. Better to do a set directly up front.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2138022133
PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2138016240
PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2138020354


More information about the nio-dev mailing list