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

Change the default Console implementation back to the built-in one in `java.base` module

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • medium
    • System.console() will return null if the underlying host environment does not provide a terminal. This was the behavior prior to JDK 22, but applications developed after that may not expect System.console() to return null when no terminal is attached.
    • Other
    • Implementation

      Summary

      Change System.console() to return the Console implementation from the java.base module rather than Console implementation built on JLine.

      Problem

      The JDK has included a JLine based Console implementation since JDK 20. This Console implementation provides a richer experience and works in virtual terminal environment, e.g. IDEs. The JLine Console implementation was opt-in via a system property on the command line in JDK 20 and JDK 21. It became the default Console implementation in JDK 22.

      Although the JLine Console implementation provides a better user experience it has turned out to be difficult to maintain and there are several issues. Examples are terminal escape sequence handling (https://bugs.openjdk.org/browse/JDK-8348052) and signal handling (https://bugs.openjdk.org/browse/JDK-8346805).

      Solution

      Revert System.console() to JDK 21 behavior and return the Console implementation from java.base by default.

      Part of the motivation for recent work on Console has been on the efforts to make it easier for new developers to start started and to write a simple interactive programs. JEP 477 "Implicitly Declared Classes and Instance Main Methods" introduced java.io.IO which was implemented on java.io.Console. The next phase of this work, JEP "Compact Source Files and Instance Main Methods" replaces java.io.IO with a new class java.lang.IO that will be implemented on the standard streams (System.in/out/err). This removes some of the need for Console to provide rich experience.

      If required, the jdk.console system property will continue to allow the richer/JLine Console implementation be selected, just as it was in JDK 20 and JDK 21.

      Specification

      N/A. Behavior change only.

            naoto Naoto Sato
            naoto Naoto Sato
            Alan Bateman, Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: