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

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Jul 14, 2025

This accompanies the fix for JDK-8361613, which restricts System.console() to return a Console instance only when both standard input and output are connected to a terminal. The change here is solely a specification clarification and tightening of the java.io.Console javadoc to reflect this behavior. We are separating the spec clarification because the fix itself may be backported to prior LTS releases without requiring a Maintenance Review process.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8361981 to be approved

Issues

  • JDK-8361972: Clarify the condition of System.console() about standard input/output (Bug - P4)
  • JDK-8361981: Clarify the condition of System.console() about standard input/output (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26299/head:pull/26299
$ git checkout pull/26299

Update a local copy of the PR:
$ git checkout pull/26299
$ git pull https://git.openjdk.org/jdk.git pull/26299/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26299

View PR using the GUI difftool:
$ git pr show -t 26299

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26299.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 14, 2025

👋 Welcome back naoto! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 14, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Jul 14, 2025
@openjdk
Copy link

openjdk bot commented Jul 14, 2025

@naotoj The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jul 14, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 14, 2025

Webrevs

* 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
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.

If we are claiming that System.console() should only return a "Console instance only when both standard input and output are connected to a terminal." then is the may wording not restrictive enough? Or is that nuance negligible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Intention here is that, we do want to restirct to not return JLine based Console when either/both of stdin/out is redirected, I think we would not want to restrict them as the spec. For example, System.console() in jshell returns non-null, even if the remote JVM is not-attached to a terminal. I will describe this sublety in the CSR

Copy link
Member

Choose a reason for hiding this comment

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

OK, I see your point. It is a hint as to what the behavior of this implementation does, but not enforced in the specification by any means as indicated by the may wording. Nit: if that is the case, then shouldn't there technically be minimal compatibility risk in the CSR, since nothing is being "enforced" specification wise.

@@ -45,8 +45,9 @@
* 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.

Copy link
Member

@justin-curtis-lu justin-curtis-lu left a comment

Choose a reason for hiding this comment

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

New wording lgtm.

* 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants