Is there really a resource leak if I close the inner stream?
I ran a dynamic code analysis tool on one of our programs and this pattern
was identified as a resource leak:
...
FileInputStream fileInputStream = new FileInputStream(file);
try {
data = someMethod(new BufferedInputStream(fileInputStream));
// Assume that someMethod(InputStream) internally reads the stream
// until BufferedInputStream.read() returns -1.
...
}
finally {
...
try {
fileInputStream.close();
} catch (IOException e) {
...
}
}
Specifically, the analysis tool marked the new BufferedInputStream(...)
call as a resource leak because it is never closed. In this pattern,
however, the underlying stream fileInputStream is closed and the
BufferedInputStream goes out of scope.
Given this situation, is this actually a resource leak?
No comments:
Post a Comment