daguimu opened a new issue, #10208: URL: https://github.com/apache/rocketmq/issues/10208
### Before Creating the Bug Report - [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq/discussions). - [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq/issues) and [GitHub Discussions](https://github.com/apache/rocketmq/discussions) of this repository and believe that this is not a duplicate. - [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ. ### Runtime platform environment All platforms ### RocketMQ version develop branch (latest) ### JDK Version All ### Describe the Bug In `IOTinyUtils.copyFile()`, `FileOutputStream` and `FileInputStream` are created inline as arguments to `getChannel()`: ```java tc = new FileOutputStream(tf).getChannel(); sc = new FileInputStream(sf).getChannel(); ``` The underlying stream references are lost. While closing the `FileChannel` typically closes the underlying stream, if an exception occurs between the two lines (e.g., `FileInputStream` constructor throws because the source file is locked), the already-created `FileOutputStream` will never be closed, leaking a file descriptor. Additionally, this pattern makes the resource ownership unclear and is flagged by static analysis tools (SpotBugs, SonarQube). ### Steps to Reproduce 1. Call `IOTinyUtils.copyFile()` with a valid target file and a source file that throws on `FileInputStream` construction 2. The `FileOutputStream` (and its channel) created on the previous line is leaked ### What Did You Expect to See? All resources should be properly closed using try-with-resources pattern. ### What Did You See Instead? Potential file descriptor leak. ### Additional Context - File: `common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java:92-93` - Fix: Convert to try-with-resources pattern -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
