Many frameworks of API have a recommended method to close streams to avoid all the boilerplate of checking for null and catching exception.
For example, in Maven, it's IOUtil.close(stream).
Findbugs don't know of this method and reports "Method may fail to clean up stream or resource" although the code makes good usage of one of this close methods.
Could FindBugs interpret a <blah>.close(stream) method as the same effect as stream.close() when it comes to analysing for stream leaks?</blah>
You probably should try to use @javax.annotation.WillClose on the method.
The problem with unannotated method is that no one guarantees FB that they will really close stream. In case of annotated methods FB at least knows the intent.
Where should this annotation be? On the IOUtil.close() method ?
Yes, I guess, I don't know the maven code :-)
The code of WillClose says:
/**
*/
public @interface WillClose {}
Thanks, I reported you suggestion there: https://jira.codehaus.org/browse/PLX-471
And could findbugs suggest addition of the @WillClose annotations on method called "close" and taking as argument a Stream?
Please change this request title/description accordingly or close this one and create another enhancement request.
I created https://sourceforge.net/p/findbugs/bugs/1238/ . However, I don't find a link to close this report. Do someone need special permissions to do this?
Closed, followup: https://sourceforge.net/p/findbugs/bugs/1238/