Skip to content

fix: preserve stderr during JLine installation - #13387

Closed
efegokdemir wants to merge 1 commit into
apache:maven-3.10.xfrom
efegokdemir:efe/maven-cli-stderr-13380
Closed

efegokdemir wants to merge 1 commit into
apache:maven-3.10.xfrom
efegokdemir:efe/maven-cli-stderr-13380

Conversation

@efegokdemir

@efegokdemir efegokdemir commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13380.

AnsiConsole.systemInstall() wraps both standard streams around the terminal output. Maven attaches that terminal to stdout, so -Dorg.slf4j.simpleLogger.logFile=System.err still sent logs to stdout.

Keep the original stderr stream after JLine installs its wrappers and restore it again during uninstall. The regression test checks that both installation and cleanup preserve stderr.

Tests

  • mvn -pl maven-embedder,maven-jline -Dtest=MavenCliTest,MessageUtilsTest -Dsurefire.failIfNoSpecifiedTests=false -am test — passed (19 tests).
  • mvn -Prun-its verify — passed. The 3.10.x branch has no run-its profile, so this ran the full default verify lifecycle without the separate Core IT suite.
  • mvn -pl apache-maven -am -DskipTests package — passed.
  • mvn -pl maven-jline spotless:check and git diff --check — passed.
  • The new regression test failed before the fix because System.err became JLine's AnsiPrintStream; it passes with this change. A packaged CLI run now sends 593 bytes to stderr and none to stdout with the property, while default logging remains on stdout.

Checklist

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
  • Run mvn verify to make sure basic checks pass.
  • You have run the Core ITs successfully. The Core IT suite is not present in this 3.10.x checkout.
  • I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004

JLine's AnsiConsole wraps both standard streams around the terminal output, which sends stderr through stdout in Maven's terminal setup. Restore the original standard error stream after installation and uninstallation, and cover the stream preservation with a regression test.
@github-actions

This comment has been minimized.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The fix is correct: capturing System.err before AnsiConsole.systemInstall() runs on the background thread and restoring it in a finally block cleanly solves the stream-redirection bug. Concurrency model is sound — the systemErr field write happens-before the read in doSystemUninstall() via the CompletableFuture chain. The defensive restore in doSystemUninstall() is belt-and-suspenders against class-loading-order edge cases and does no harm. Pre-fix test validation confirmed: test fails without the fix, passes with it.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet

gnodet commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Closing in favour of the upstream JLine fix. The root cause has been addressed in JLine 4.4.8 via jline/jline3#2317 — AnsiConsole.ansiStream() now routes each stream to its correct fd instead of unconditionally using terminal.output() for both. Bumping Maven's JLine dependency to 4.4.8 will resolve the issue without any Maven-side workaround.

@gnodet gnodet closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants