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

Justin Lu jlu at openjdk.org
Thu Jul 17 17:41:48 UTC 2025


On Thu, 17 Jul 2025 16:48:20 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Console.java line 51:
>> 
>>> 49:  * console. Regardless of how the virtual machine was created, it may not
>>> 50:  * have a console if either the standard input or output stream is
>>> 51:  * redirected.
>> 
>> 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.
>
> I was considering the case for `jshell`, where its `System.console()` returns a `Console` instance regardless of the `isTTY` state:
> 
> https://github.com/openjdk/jdk/blob/bd55d7a49514da9fa4de0d4a372956e21deab4d2/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java#L70
> 
> That led me to use `may` in the updated spec. I'd appreciate your suggestions on wording.

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?

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

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


More information about the core-libs-dev mailing list