Skip to content

Fix #1275: stop using PrintWriter in AbstractLineAggregatingHandler to avoid swallowing IOExceptions - #1348

Merged
elharo merged 3 commits into
masterfrom
fix/issue-1275-printwriter-swallowed-io
Aug 5, 2026
Merged

Fix #1275: stop using PrintWriter in AbstractLineAggregatingHandler to avoid swallowing IOExceptions#1348
elharo merged 3 commits into
masterfrom
fix/issue-1275-printwriter-swallowed-io

Conversation

@elharo

@elharo elharo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

fixes #1275.

AbstractLineAggregatingHandler.addToArchive wrapped the aggregation output stream in a PrintWriter. By design, PrintWriter catches IOException internally and only records it via checkError(). Any write failure during aggregation was therefore silently swallowed, and a truncated or empty aggregated file was added to the archive without any error surfacing.

Changes

  • Replaced PrintWriter with OutputStreamWriter in AbstractLineAggregatingHandler.addToArchive. Write failures now propagate as IOException and are wrapped in an ArchiverException by the existing catch block.
  • Added a small protected seam newAggregationOutputStream(Path) so the write target can be replaced in tests.
  • Added regression test AbstractLineAggregatingHandlerTest.addToArchiveShouldPropagateIOExceptionWhenAggregationWriteFails that injects an OutputStream which fails on write and asserts that addToArchive throws ArchiverException.

The test fails on the old code (PrintWriter swallows the exception, nothing is thrown) and passes with the fix.

DefaultMessageHolder also uses PrintWriter, but it wraps an in-memory StringWriter which cannot throw IOException; it is left unchanged (and Throwable.printStackTrace requires a PrintWriter).

Verification

  • mvn verify: BUILD SUCCESS, 269 tests pass (1 new regression test).
  • Behavior of the success path is unchanged: lines are written followed by the platform line separator, identical to the previous println behavior.

@elharo elharo added the bug Something isn't working label Aug 4, 2026
@elharo
elharo merged commit a3cfb8f into master Aug 5, 2026
15 checks passed
@elharo
elharo deleted the fix/issue-1275-printwriter-swallowed-io branch August 5, 2026 10:43
@github-actions github-actions Bot added this to the 3.8.1 milestone Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop using PrintWriter

2 participants