RFR: 8361613: System.console() should only be available for interactive terminal
Andrey Turbanov
aturbanov at openjdk.org
Fri Jul 11 20:37:39 UTC 2025
On Fri, 11 Jul 2025 18:46:14 GMT, Naoto Sato <naoto at openjdk.org> wrote:
> In prior JDK releases, `System.console()` could return a `Console` instance even when the JVM was not attached to an interactive terminal. This could lead to confusion, particularly when input was not from a keyboard or output was redirected, such as to or from a file or pipe, especially when using methods like `readPassword()`. Starting with JDK 25, the default behavior has changed: `System.console()` now returns `null` if standard input and/or output is redirected. However, if a JLine-based Console implementation is explicitly specified via the system property `-Djdk.console=jdk.internal.le`, the previous behavior may still occur.
> This PR aims to align the behavior of the JLine-based `Console` implementation with the default `System.console()` behavior. The actual code change is a one-liner in `JdkConsoleProviderImpl.java`; the rest of the changes are adjustments to test cases to reflect the updated behavior. A corresponding CSR has also been drafted.
test/jdk/java/io/Console/LocaleTest.java line 52:
> 50: */
> 51: public class LocaleTest {
> 52: private static final Calendar TODAY = new GregorianCalendar(2024, Calendar.APRIL, 22);
Suggestion:
private static final Calendar TODAY = new GregorianCalendar(2024, Calendar.APRIL, 22);
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26273#discussion_r2201798509
More information about the core-libs-dev
mailing list