You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AnsiConsole.systemInstall() always replaces System.err even when the terminal is backed by stdout #2316
AnsiConsole.systemInstall() unconditionally replaces both System.out and System.err with AnsiPrintStream instances, regardless of which system stream the underlying terminal is actually attached to:
Both out and err are built by ansiStream(), which always uses terminal.output() as the underlying output target. That single stream is backed by whichever fd the terminal was opened on — fd 1 when selected via SysOut, fd 2 when selected via SysErr.
Consequence
When the terminal is selected via SysOut (stdout is a tty):
terminal.output() → fd 1
err AnsiPrintStream → fd 1 (stdout)
System.setErr(err) redirects System.err to stdout
The symmetric case holds for SysErr.
This means the stream that did not win the selection has its fd silently replaced by the winner's fd. Anything written to System.err ends up on stdout (and vice-versa in the SysErr case).
Real-world impact
Apache Maven calls TerminalBuilder.builder().systemOutput(SysOut) before AnsiConsole.systemInstall(). When a user sets -Dorg.slf4j.simpleLogger.logFile=System.err, they expect log output on stderr. Instead it arrives on stdout, because systemInstall() replaced System.err with an AnsiPrintStream backed by fd 1. See apache/maven#13387 for the workaround.
Expected behaviour
systemInstall() should only replace the stream that corresponds to the system stream the terminal is actually attached to:
Terminal selected via SysOut → replace System.out, leave System.err alone (or wrap it against system_err if it is itself a tty)
Terminal selected via SysErr → replace System.err, leave System.out alone (or wrap it against system_out if it is itself a tty)
The information needed to make this decision is already available: ((TerminalExt) terminal).getSystemStream() returns the winning SystemStream.
Correct fix
The ideal fix would provide full ANSI support for both streams when both are ttys — this would require opening a second native terminal on the other fd. At minimum, when only one stream is a tty, the other should be left as-is (or wrapped with AnsiMode.Strip against the actual system_out/system_err PrintStream) rather than being silently redirected to the tty's fd.
Activity
gnodet commentedon Oct 9, 2026
Apache Maven workarounds:
-Dorg.slf4j.simpleLogger.logFile=System.errapache/maven#13380fix: AnsiConsole.systemInstall() no longer redirects the non-terminal…