Skip to content

Fix #1998: use try-with-resources in test file utilities - #2056

Merged
elharo merged 1 commit into
masterfrom
fix-1998-try-with-resources
Aug 9, 2026
Merged

elharo merged 1 commit into
masterfrom
fix-1998-try-with-resources

Conversation

@elharo

@elharo elharo commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #1998

Convert manual try-catch-finally stream handling to try-with-resources in the test utilities:

  • TestFileUtils: copyFile, readBytes, writeBytes, readProps, writeProps
  • TestFileProcessor: write(File, String), write(File, InputStream), copy(File, File, ProgressListener)

Resources created inside each method are now closed reliably (with close exceptions properly suppressed), eliminating the leak when an explicit close() throws before the finally block. The caller-supplied InputStream in TestFileProcessor.write/copy remains intentionally unclosed, matching prior behavior.

No new tests required.

@elharo
elharo requested a review from ppkarwasz August 9, 2026 17:36

@gnodet gnodet 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 — Clean, correct conversion of 8 methods across two test utility files from manual try-catch-finally to try-with-resources. All conversions are behavior-preserving:

  • The mkdirs reordering in copy/copyFile is safe and actually a slight improvement (no resources open when mkdirs runs).
  • The caller-supplied InputStream in TestFileProcessor.write(File, InputStream) remains correctly unmanaged.
  • Exception suppression via try-with-resources is strictly better for diagnostics than the original swallowed close exceptions.
  • Net -130 lines of boilerplate with no functional risk.

CI should pass before merge.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

@elharo
elharo merged commit df3b5d2 into master Aug 9, 2026
25 checks passed
@elharo
elharo deleted the fix-1998-try-with-resources branch August 9, 2026 20:36
@github-actions github-actions Bot added this to the 2.0.22 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leaky stream handling in test utilities (TestFileUtils, TestFileProcessor)

2 participants