RFR: 8340404: Clarify CharsetProvider deployment on application module path [v5]
Alan Bateman
alanb at openjdk.org
Sat Sep 21 05:58:38 UTC 2024
On Fri, 20 Sep 2024 23:37:18 GMT, Justin Lu <jlu at openjdk.org> wrote:
>>> Did you have any comments on the current doc change?
>>
>> I've been slow to reply on that because I'm not 100% sure if the spec is correct. Can you double check that the CCL is actually used. I think it uses the system class loader, and maybe the platform class loader for the extended charsets.
>
> Hi Alan,
>
> I think you're right that the CCL is not used.
>
> The standard charsets are loaded via the SystemClassLoader, the extended are loaded via the platformClassLoader, and BazProvider does appear to be loaded via the SystemClassLoader. See below,
>
>
> // Assert default context class loader is the system class loader
> Thread.currentThread().getContextClassLoader(); // default context class loader -> jdk.internal.loader.ClassLoaders$AppClassLoader at 1d81eb93
> ClassLoader.getSystemClassLoader(); // system class loader -> jdk.internal.loader.ClassLoaders$AppClassLoader at 1d81eb93
>
> // Change the default context class loader
> Thread.currentThread().setContextClassLoader(new FooLoader()); // Change default context class loader to not be the system
>
> // Check the class loaders for the various Charsets
> Charset.availableCharsets().get("utf-8").getClassLoader(); // standard -> null
> Charset.availableCharsets().get("Big5").getClassLoader(); // extended -> jdk.internal.loader.ClassLoaders$PlatformClassLoader at 55a95ab1
> Charset.availableCharsets().get("BAZ").getClassLoader(); // provider -> jdk.internal.loader.ClassLoaders$AppClassLoader at 1d81eb93
> Thread.currentThread().getContextClassLoader(); // context class loader -> CharsetProviderAsModuleTest$FooLoader at 1d15c6cc
>
>
> Can we simply omit the line:
>
> "_Charset providers are looked up via the current thread's context class loader_".
Thanks for checking. I remember [JDK-4619777 ](https://bugs.openjdk.org/browse/JDK-4619777) and it's possible there are one or two other JBS issue on the topic. It may be been interesting to include a charset provider with a dynamically loaded application at one point but seems less interesting in 2024. So I think we should just update the spec to align with the long standing behavior, meaning specify that the charset provider must be visible to the system class loader. I think "by some other platform-specific means" by can be dropped too.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21076#discussion_r1769483298
More information about the nio-dev
mailing list