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, i.e., a Console will not be available if either standard input or output (or both) is redirected. Also, modify the spec of isTerminal()
method to return always true
.
Specification
Change the last sentence of the second paragraph of the class description of java.io.Console
as follows:
* was launched. If the virtual machine is started automatically, for
* example by a background job scheduler, then it may not
- * have a console.
+ * have a console. Regardless of how the virtual machine was created,
+ * it will not have a console if either the standard input or output
+ * stream is redirected.
* <p>
* If this virtual machine has a console then it is represented by a
Change the method description of isTerminal()
as:
* {@return {@code true} 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.
+ * This method always returns {@code true}, since {@link System#console()}
+ * provides a {@code Console} instance only when both standard input and
+ * output are unredirected, that is, when running in an interactive terminal.
*
- csr of
-
JDK-8361972 Clarify the condition of System.console() about standard input/output
-
- In Progress
-