RFR: 8298971: Move Console implementation into jdk internal package [v2]

Naoto Sato naoto at openjdk.org
Tue Dec 20 22:13:50 UTC 2022


On Tue, 20 Dec 2022 14:24:28 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Removed JdkConsoleProviderImpl, caching INSTANCE
>
> src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java line 336:
> 
>> 334:     public JdkConsole console(boolean isTTY, Charset charset) {
>> 335:         if (isTTY) {
>> 336:             if (INSTANCE == null) {
> 
> This would need a double checked locking, isn't it? Something like:
> 
> if (INSTANCE == null) {
>    synchronized (JdkConsoleImpl.class) {
>       if (INSTANCE != null) {
>           return INSTANCE;
>       }
>       ...// rest of the current code that's in if block
> 
> 
> Having said that perhaps the singleton instance isn't needed here and the `java.io.Console` deal with the caching?

You are right. `JdkConsoleImpl` is instantiated within the static initializer of `Console`, there is no need to cache it. `Console.cons` is guaranteed to be a singleton. Removed tha caching altogther.

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

PR: https://git.openjdk.org/jdk/pull/11729


More information about the core-libs-dev mailing list