Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8309141

JLine as the default Console provider

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • behavioral
    • medium
    • Hide
      `System.console()` may return instances in more contexts than it does now. For example, a console provider may return an instance for `System.console()` for cases where it didn't previously. So some applications that expect `System.console() == null` implying non-TTY environment would see different results.
      Show
      `System.console()` may return instances in more contexts than it does now. For example, a console provider may return an instance for `System.console()` for cases where it didn't previously. So some applications that expect `System.console() == null` implying non-TTY environment would see different results.
    • Java API
    • SE

      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() 

            naoto Naoto Sato
            naoto Naoto Sato
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: