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

Naoto Sato naoto at openjdk.org
Fri Jul 11 22:07:01 UTC 2025


> 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.

Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:

  Update test/jdk/java/io/Console/LocaleTest.java
  
  Co-authored-by: Andrey Turbanov <turbanoff at gmail.com>

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/26273/files
  - new: https://git.openjdk.org/jdk/pull/26273/files/ea72f445..82773085

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=26273&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26273&range=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/26273.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26273/head:pull/26273

PR: https://git.openjdk.org/jdk/pull/26273


More information about the core-libs-dev mailing list