android icon indicating copy to clipboard operation
android copied to clipboard

[TECHNICAL] Stream handling and double-close in `UploadFileFromContentUriWorker`

Open dataCenter430 opened this issue 8 months ago • 5 comments

In copyFileToLocalStorage(), streams are not closed safely and the output stream is closed twice.

  • Double-close: outputStream is closed inside outputStream.use { ... }, then outputStream.close() is called again. The second close is redundant and can cause issues.
  • Leak on error: inputStream is not used inside a use block. If inputStream?.copyTo(fileOut) throws, the input stream is never closed.

Suggested fix: Use inputStream?.use { it.copyTo(fileOut) } so the input stream is always closed, and remove the explicit inputStream?.close() and outputStream.close() calls so only use is responsible for closing.

dataCenter430 avatar Mar 05 '26 18:03 dataCenter430

Hi @joragua, hope you're doing well! I'm new here and recently discovered this repository. I really enjoy Android development and would love the opportunity to contribute. If this issue is still available, I'd be happy to work on it. Thanks! 😊

dataCenter430 avatar Mar 05 '26 18:03 dataCenter430

Please submit a pull request right away. Thank you!

DeepDiver1975 avatar Mar 05 '26 21:03 DeepDiver1975

okay, I got it, thanks

dataCenter430 avatar Mar 05 '26 21:03 dataCenter430

Hey, @DeepDiver1975 I've created the PR for this issue. could you pls review it, when you have a chance? thank you.

dataCenter430 avatar Mar 05 '26 22:03 dataCenter430

@dataCenter430 thanks for your engagements and contributions. We'll review the code, give you some tips and then, test and QA it. Please keep tuned

jesmrec avatar Mar 06 '26 07:03 jesmrec