[#2514] Flush out/err PrintWriters after CommandLine.execute - #2527
Open
kalayciburak wants to merge 1 commit into
Open
[#2514] Flush out/err PrintWriters after CommandLine.execute#2527kalayciburak wants to merge 1 commit into
kalayciburak wants to merge 1 commit into
Conversation
print() does not trigger autoFlush on PrintWriter. Flush the root and parsed command writers in a finally block so buffered output is not lost when the JVM exits immediately after execute().
kalayciburak
force-pushed
the
fix/2514-flush-out-err-after-execute
branch
from
August 16, 2026 09:43
200aaaa to
8e6ce5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CommandLine.executedid not flushout/errafter the command finished.PrintWriterautoFlush only applies toprintln/printf/format, so data written withprint()could stay buffered and disappear when the JVM exits right afterexecute().This change flushes the root command and every parsed command-line's writers in a
finallyblock afterexecute.Fixes #2514
Test plan
./gradlew :test --tests picocli.ExecuteTest.testExecuteFlushesOutAfterPrintWithoutNewline --tests picocli.ExecuteTest.testExecuteFlushesErrAfterPrintWithoutNewline(RED before fix, GREEN after)./gradlew :test --tests picocli.ExecuteTest— 86/86 GREEN./gradlew :test— 2283 tests, 0 failures, 32 skipped