Menu

#1238 Suggest to annotate method that close a given stream to set @WillClose annotation

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

When a method takes a stream or resource as input and close it in its content using directly .close() or another @WillClose annotated method on the same stream, FindBugs should report that it should also be annotated with @WillClose.

With that, we can hope to reduce the amount of false positive on stream leaks.

Discussion

  • William Pugh

    William Pugh - 2014-01-08

    We do look at method names, and we generally treat methods named close as being annotated with @WillClose. See attached sample.

    A lot of people don't want to add @WillClose annotations, because that adds a JSR-305 dependency to their project.

    Do you have an example of code where a call to a close(...) method isn't being properly handled?

     
  • William Pugh

    William Pugh - 2014-01-08
    • status: open --> pending-works-for-me
    • assigned_to: William Pugh
    • Group: 2.0.3 --> 3.0.0
     
  • Mickael Istria

    Mickael Istria - 2014-01-08

    I'm using FindBugs 2.2.0 in Eclipse. and I get the report with a
    InputStream stream = null;
    try {
    stream = new FileInputStream(...)
    } catch (Exception ex) {
    throw new WrapException(ex);
    } finally {
    IOUtil.close(stream); // IOUtil comes from codehaus plexus
    }

    Should I try a newer FindBugs version?

     
  • William Pugh

    William Pugh - 2014-01-09

    I can't reproduce the warning you are seeing, either with 2.0.2 or HEAD. See attached. Can you send me a compete, compilable source file, that shows the problem, along with a class file?

     
  • Andrey Loskutov

    Andrey Loskutov - 2014-06-19
    • status: pending-works-for-me --> closed-works-for-me
    • Group: 3.0.0 --> 2.0.3
     

Log in to post a comment.

MongoDB Logo MongoDB