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 2 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
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/io/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
* 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.
* example by a background job scheduler, then it may not have a
* console. Regardless of how the virtual machine was created, it may not
* have a console if either the standard input or output stream is
* redirected.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify what the intent of "it may not have a console" is? Initially I though the intention was that there is no Console when either stdout or stdin is redirected. However, the sentence suggests there may or may not be a Console.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was considering the case for jshell, where its System.console() returns a Console instance regardless of the isTTY state:

return console = new RemoteConsole(remoteOutput, remoteInput);

That led me to use may in the updated spec. I'd appreciate your suggestions on wording.

Copy link
Member

Choose a reason for hiding this comment

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

Since the decision of whether a console exists is dependent on the implementation as specified,

Whether a virtual machine has a console is dependent upon the underlying platform

And the existing wording in this paragraph uses open-ended words such as "may" and "typically", it makes sense to me that this change would follow the same style of wording. If you wanted to concretely define what this implementation does, using one of the @impl tags to describe the behavior could be an option?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so the intent is to specify that it is implementation or configuration specific as to whether there is a Console when standard input or output, but not both, are redirected, is that right? What should users expect isTerminal to return in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

For the jshell case, I think it can return true from its isTerminal() as it is infact interactive environment. That means all the Console implementations return true so that we can replace that "may not have a Console" with "will not have a Console", which is clearer.

* <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
Expand Down