RFR: 8298971: Move Console implementation into jdk internal package
Jaikiran Pai
jpai at openjdk.org
Tue Dec 20 14:48:50 UTC 2022
On Tue, 20 Dec 2022 14:37:10 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java line 179:
>>
>>> 177: private Writer out;
>>> 178: private PrintWriter pw;
>>> 179: private Formatter formatter;
>>
>> Hello Naoto, I think some of these can be made `final`.
>
> Actually, I see that it isn't possible for these to be final because we set these up in the `console(...)` instance method of this class. That's because this `JdkConsoleImpl` implements both the `JdkConsole` interface and the `JdkConsoleProvider` interface.
Do you think we could separate out this class into 2 separate implementations? Just like we do in the `jdk.internal.org.jline.JdkConsoleProviderImpl`? That could perhaps make this implementation similar to that other one and a bit simpler? So something like:
package jdk.internal.io;
public final class JdkConsoleProviderImpl implements JdkConsoleProvider {
private static volatile JdkConsole INSTANCE;
@Override
public JdkConsole console(boolean isTTY, Charset charset) {
.....
// construct and return a (JdkConsoleImpl instance)
}
public static synchronized JdkConsole getJdkConsole(Charset cs) {
return INSTANCE != null ? INSTANCE : new JdkConsoleImpl(cs);
}
private static final class JdkConsoleImpl implements JdkConsole {
private final Charset charset;
private final Object readLock;
private final Object writeLock;
private final Reader reader;
private final Writer out;
private final PrintWriter pw;
private final Formatter formatter;
private char[] rcb;
private boolean restoreEcho;
private boolean shutdownHookInstalled;
private JdkConsoleImpl(Charset cs) {
this.charset = cs;
....
}
// other methods from JdkConsole
}
}
-------------
PR: https://git.openjdk.org/jdk/pull/11729
More information about the core-libs-dev
mailing list