-
Notifications
You must be signed in to change notification settings - Fork 1.9k
GROOVY-8373: Fix resource leak in filterLine Writable.writeTo method #2352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The filterLine method returns a Writable whose writeTo method reads from a BufferedReader but never closes it, causing the underlying file handle to remain open and cause resource leaks. This fix wraps the filtering logic in writeTo within a try-finally block to ensure the BufferedReader is closed after use.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2352 +/- ##
==================================================
- Coverage 67.0080% 67.0065% -0.0014%
+ Complexity 29357 29355 -2
==================================================
Files 1382 1382
Lines 116619 116620 +1
Branches 20444 20444
==================================================
- Hits 78144 78143 -1
- Misses 32039 32040 +1
- Partials 6436 6437 +1
🚀 New features to boost your workflow:
|
|
What if |
|
Frankly the general Writable-concept has its problems. I was fixing the issue in GROOVY-8373 only. If you look at:
then you have one readline that closes the writer, while the other returns a writer, which you are, I guess, supposed to reuse. And in that manner it would be wrong to have it closed in the method I changed. But does the API make sense like this? Well, not part of the issue as I said ;) |
|
Certainly this change is a step in the right direction. Is it possible to delay the creation of the buffered reader until |
|
The
The |
|
Since we "read all available lines" form the reader I think it is better to close it. Also aligns more with the other method. Yes, the BufferedReader creation can be moved into writeTo. I think that is a good idea. |
The filterLine method returns a Writable whose writeTo method reads from a BufferedReader but never closes it, causing the underlying file handle to remain open and cause resource leaks.
This fix wraps the filtering logic in writeTo within a try-finally block to ensure the BufferedReader is closed after use.