Skip to content

8361972: Clarify the condition of System.console() about standard input/output #26299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/java.base/share/classes/java/io/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@
* underlying platform and also upon the manner in which the virtual
* 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
* 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
Copy link
Member

@justin-curtis-lu justin-curtis-lu Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might read easier if we reword the structure of the sentence to make it more concise.

E.g.

The virtual machine may not have a console if started automatically, (e.g., by a background scheduler) or if either the standard input or output has been redirected.

* 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
* unique instance of this class which can be obtained by invoking the
* {@link java.lang.System#console()} method. If no console device is
* {@link System#console()} method. If no console device is
* available then an invocation of that method will return {@code null}.
* <p>
* Read and write operations are synchronized to guarantee the atomic
Expand Down Expand Up @@ -535,18 +537,14 @@ public Charset charset() {
/**
* {@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.
*
* @since 22
*/
public boolean isTerminal() {
return istty;
return true;
}

private static UnsupportedOperationException newUnsupportedOperationException() {
Expand Down