[Bug] Fix resource leak: properly close RandomAccessFile and FileChannel using try-with-resources#10231
Open
Senrian wants to merge 2 commits intoapache:developfrom
Open
[Bug] Fix resource leak: properly close RandomAccessFile and FileChannel using try-with-resources#10231Senrian wants to merge 2 commits intoapache:developfrom
Senrian wants to merge 2 commits intoapache:developfrom
Conversation
…ing try-with-resources
lizhimins
reviewed
Mar 30, 2026
| } | ||
|
|
||
| try { | ||
| try (RandomAccessFile raf = new RandomAccessFile(fileName, "rw"); |
Fix reviewer feedback: use read-only mode ("r") since the file is only being read, not written.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10231 +/- ##
==========================================
Coverage 48.92% 48.93%
- Complexity 13375 13379 +4
==========================================
Files 1373 1373
Lines 99908 99923 +15
Branches 12901 12903 +2
==========================================
+ Hits 48878 48895 +17
+ Misses 45096 45065 -31
- Partials 5934 5963 +29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Bug Description
In
DumpCompactionLogCommand.java, aRandomAccessFileis created to obtain aFileChannel, but neither theRandomAccessFilenor theFileChannelis ever closed. This causes a file descriptor leak.Issue: #10218
Fix
Use try-with-resources to ensure both
RandomAccessFileandFileChannelare properly closed:This follows the recommended Java practice for resource management.