JDK-8361981 : Clarify the condition of System.console() about standard input/output
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: 26
  • Submitted: 2025-07-11
  • Updated: 2025-07-14
Related Reports
CSR :  
Description
Summary
-------

Clarify the condition of System.console() about standard input/output

Problem
-------
JDK-8361613 restricts the JLine based Console implementation to return the instance from System.console() only when both standard input and output are attached to the terminal. It is desirable to clarify the java.io.Console specification regarding the `Console` availability when standard input / output may not be connected to a terminal.

Solution
--------

Modify the class description in the `java.io.Console` where `System.console()` is mentioned to include the condition about the standard input/output.

Specification
-------------
Change the last sentence of the second paragraph of the class description of `java.io.Console` as follows:
```
@@ -43,12 +43,13 @@
   * machine is invoked.  If the virtual machine is started from an
   * interactive command line without redirecting the standard input and
   * output streams then its console will exist and will typically be
   * connected to the keyboard and display from which the virtual machine
   * was launched.  If the virtual machine is started automatically, for
-  * example by a background job scheduler, then it may not
-  * have a console.
+  * example by a background job scheduler, or if one or both of the
+  * standard input or output has been redirected, then it may not have a
+  * console.
   * <p>
   * If this virtual machine has a console then it is represented by a
   * unique instance of this class which can be obtained by invoking the
   * {@link java.lang.System#console()} method.  If no console device is
   * available then an invocation of that method will return {@code null}.
```