Before Creating the Bug Report
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():
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
- Call
IOTinyUtils.copyFile() with a valid target file and a source file that throws on FileInputStream construction
- 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
Before Creating the Bug Report
Runtime platform environment
All platforms
RocketMQ version
develop branch (latest)
JDK Version
All
Describe the Bug
In
IOTinyUtils.copyFile(),FileOutputStreamandFileInputStreamare created inline as arguments togetChannel():The underlying stream references are lost. While closing the
FileChanneltypically closes the underlying stream, if an exception occurs between the two lines (e.g.,FileInputStreamconstructor throws because the source file is locked), the already-createdFileOutputStreamwill 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
IOTinyUtils.copyFile()with a valid target file and a source file that throws onFileInputStreamconstructionFileOutputStream(and its channel) created on the previous line is leakedWhat 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
common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java:92-93