RFR: 8361613: System.console() should only be available for interactive terminal [v3]

Xueming Shen sherman at openjdk.org
Tue Jul 15 14:35:42 UTC 2025


On Tue, 15 Jul 2025 13:29:03 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/System.java line 244:
>> 
>>> 242:      *
>>> 243:      * @return  The system console, if any, otherwise {@code null}.
>>> 244:      * @see Console
>> 
>> The method declaration already links to Console so I don't think we need another link in the "See also" section.
>
> Maybe I missed it, but do we have anything to make it clear that it returns null if either stdin or stdout are redirected?

we do have wordings like " If the virtual machine is started from an interactive command line without redirecting the standard input AND output streams then its console will exist ..." and "If no console device is
available then an invocation of that method will return <tt>null</tt>" from the very beginning. not very "straightforward" but i think it's clear enough?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26273#discussion_r2207686213


More information about the compiler-dev mailing list