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

Naoto Sato naoto at openjdk.org
Mon Jul 14 19:40:40 UTC 2025


On Mon, 14 Jul 2025 18:56:11 GMT, Justin Lu <jlu at openjdk.org> wrote:

>> This accompanies the fix for [JDK-8361613](https://bugs.openjdk.org/browse/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.
>
> src/java.base/share/classes/java/io/Console.java line 49:
> 
>> 47:  * was launched.  If the virtual machine is started automatically, for
>> 48:  * example by a background job scheduler, or if one or both of the
>> 49:  * standard input or output has been redirected, then it may not have a
> 
> 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?

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

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26299#discussion_r2205665390


More information about the core-libs-dev mailing list