Menu

#1237 Interpret <blah>.close(stream) as stream.close()

2.0.3
closed-works-for-me
None
5
2014-01-08
2014-01-08
No

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>

Discussion

  • Andrey Loskutov

    Andrey Loskutov - 2014-01-08

    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.

     
  • Mickael Istria

    Mickael Istria - 2014-01-08

    Where should this annotation be? On the IOUtil.close() method ?

     
  • Andrey Loskutov

    Andrey Loskutov - 2014-01-08

    Yes, I guess, I don't know the maven code :-)
    The code of WillClose says:

    /**

    • Used to annotate a method parameter to indicate that this method will close
    • the resource.
      */
      public @interface WillClose {}
     
  • Mickael Istria

    Mickael Istria - 2014-01-08

    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?

     
  • Andrey Loskutov

    Andrey Loskutov - 2014-01-08

    Please change this request title/description accordingly or close this one and create another enhancement request.

     
  • Mickael Istria

    Mickael Istria - 2014-01-08

    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?

     
  • Andrey Loskutov

    Andrey Loskutov - 2014-01-08
    • status: open --> closed-works-for-me
    • assigned_to: Andrey Loskutov
     

Log in to post a comment.