JDK-8309141 : JLine as the default Console provider
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 22
  • Submitted: 2023-05-30
  • Updated: 2023-07-19
  • Resolved: 2023-07-19
Related Reports
CSR :  
Description
Summary
-------

Make `JLine` the default `Console` provider

Problem
-------

The initial intention for using `JLine` module for the `Console` was for a better user experience (JDK-8295803). However, the implementation was spawning native OS commands in Linux/macOS environments and caused performance degradation on some app's startup time (JDK-8299137), thus the use of `JLine` was made optional (JDK-8299689) for `Console`. So unless the user opt-in for using `JLine` via the system property, `Console` defaults to the built-in implementation.

Solution
--------

JLine implementation no longer spawns native commands with the fix to JDK-8306983, it is desirable to make the `JLine` implementation the default `Console` provider. By lazily instantiating JLine instance, the performance regression can be improved down from >4% (as in JDK-8299137) to 2%.
Also, introduce a new public method for applications which need to know whether the Console instance is a TTY environment or not, which has been simulated by `System.console() != null`.

Specification
-------------

Add the following new public method in `java.io.Console` class:

     /**
      * {@return if the {@code Console} instance is a terminal}
      * <p>
      * This method returns {@code true} if the console device, associated with the current
      * Java virtual machine, is a terminal, typically an interactive command line
      * connected to a keyboard and display.
      *
      * @implNote The default implementation returns the value equivalent to calling
      * {@code isatty(stdin/stdout)} on POSIX platforms, or whether standard in/out file
      * descriptors are character devices or not on Windows.
      *
      * @since 22
      */
     public boolean isTerminal() 


Comments
I see a release note is already planned; moving to Approved.
19-07-2023

This proposal looks good. We need System.console to return the Console when used in an IDE or other virtual terminal environments. Doing us may break the assumption System.console returns null when the console is not a terminal / interactive command line. Adding Console::isTerminal provides a supported/standard way to test this.
18-07-2023