Method may fail to close stream on exception
- by 01
I get the critical error with finbugs
The method creates an IO stream object, does not assign it to any fields, pass it to other methods, or return it, and does not appear to close it on all possible exception paths out of the method. This may result in a file descriptor leak. It is generally a good idea to use a finally block to ensure that streams are closed.
try {
...
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
...
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
if (stdInput != null) {
stdInput.close();
}
if (stdError != null) {
stdError.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
do i need to close also InputStreamReader or p.getErrorStream(it returns InputStream) ??