On Mon, 19 Dec 2022 19:23:25 GMT, Naoto Sato <na...@openjdk.org> wrote:

> Moving the built-in implementation of `Console` from `java.io` package into 
> `jdk.internal.io` package. It now implements `JdkConsole` interface and is 
> accessed through `ProxyingConsole`.

src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java line 365:

> 363:     // For convenience
> 364:     public static JdkConsole getJdkConsole(Charset cs) {
> 365:         return INSTANCE != null ? INSTANCE : new 
> JdkConsoleImpl().console(true, cs);

Would this singleton/caching be necessary? Or could we expect that the caller 
of this method would cache it (like the `java.io.Console` actually does right 
now)?
In theory, this current implementation in this method can potentially return an 
incorrect (cached) instance on a second call if the `Charset` that's passed is 
different from the one that was used by the cached instance that is returned. 
But, since we know/expect this method to be called only by the 
`java.io.Console` and with the same `Charset` instance, I think this is OK. I 
do think that if we remove the caching/singleton logic here, this class could 
be a bit more simpler.

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

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

Reply via email to