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

Naoto Sato naoto at openjdk.org
Thu Aug 21 00:53:09 UTC 2025


On Thu, 21 Aug 2025 00:17:32 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Console.java line 47:
>> 
>>> 45:  * output streams then its console will exist and will typically be
>>> 46:  * connected to the keyboard and display from which the virtual machine
>>> 47:  * was launched.  If the virtual machine is started automatically, for
>> 
>> 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.
>
> I took another look at this and I agree that some rewording is necessary. There are several inconsistencies in the wording here, e.g., between "exists / does not exist" or "the virtual machine has a console / does not have a console" or "a console / a console device". I rewrote the first couple paragraphs here to unify the wording around a console as a noun (that is, no "console device") and to use "exists / does not exist" consistently. I also made some areas a bit more definite.
> 
>     * <p> Whether a virtual machine's console exists is dependent upon the
>     * 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 generally exist and will be
>     * connected to the keyboard and display from which the virtual machine
>     * was launched. If the standard input or standard output have been
>     * redirected (for example, to a file or to a pipe), or if the virtual
>     * machine was started from a background job scheduler, the console
>     * will not exist.
>     * <p>
>     * If the console exists, then it is represented by a unique instance of this
>     * class which can be obtained by invoking the {@link System#console()} method.
>     * If the console does not exist, that method will return {@code null}.

Thanks, Stuart. Updated those paragraphs as suggested.

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

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


More information about the core-libs-dev mailing list