JDK-8359861 : System.console() is non-null even when not a TTY on WSL
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 24.0.1
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • CPU: x86
  • Submitted: 2025-06-17
  • Updated: 2025-06-27
  • Resolved: 2025-06-27
Related Reports
Relates :  
Description
A JRuby user reported that we are outputting ANSI escape sequences even when piping output to a non-TTY process like "less" or "more". The logic in JRuby determines TTYness by checking the value of java.lang.System.console(), which should be null when stdin and stdout are not both attached to a TTY. However when running in the Windows Subsystem for Linux (WSL), it appears that this is not the case; java.lang.System.console() returns a non-null ProxyingConsole instance even when output is being piped to a non-TTY process.

This most likely affects any other projects that uses java.lang.System.console() to detect a TTY, such as to provide color or bold text output.
Comments
As of JDK25, System.console() returns null unless stdin and stdout are connected to interactive terminal. This is the expected behavior if stdout is redirected to a file/pipe.
27-06-2025

Can you confirm that you don't have this issue with -Djdk.console=java.base ? Just checking as Console is switched back in JDK 25 to no longer use the jline based console by default.
18-06-2025

Example output provided by our user in the following issue: https://github.com/jruby/jruby/issues/8870#issuecomment-2981687697 Output of checking java.lang.System.console() under WSL using JRuby: $ jruby -e 'p java.lang.System.console' #<Java::JavaIo::ProxyingConsole:0x3fa247d1> $ jruby -e 'p java.lang.System.console' | more #<Java::JavaIo::ProxyingConsole:0x3fa247d1> The latter command should produce "nil" equivalent to Java "null" indicating that the console is not a TTY.
17-06-2025