Menu

#1357 Method may fail to clean up stream or resource on checked exception

3.x
closed-works-for-me
5
2015-02-21
2015-02-10
No

FindBugs version: 0.9.994
Java version: 1.7

Following is code snippet, in this even if resource is closed in finally clause, FindBugs gives error to close it.
As resource is closed using try - resource statement which is introduced in Java 1.7.

    try {
        readContent();
    } catch (IOException e) {
        e.printStackTrace();
    }

private static void readContent() throws IOException {
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("D:\\Intellij\\EclipseFormast.xml"));
        System.out.println(br.readLine());
    } finally {
        System.out.println("Gets Called");
        if (br != null)
            br.close();
    }

}

Discussion

  • Andrey Loskutov

    Andrey Loskutov - 2015-02-10

    Findbugs 0.9.994??? OMG!

    Current version is 3.0.0. Please update your installation and retest. We do not support older versions due the lack of resources.
    Regards,
    Andrey

     
  • Tagir Valeev

    Tagir Valeev - 2015-02-17
    • status: open --> closed-invalid
    • assigned_to: Tagir Valeev
     
  • Tagir Valeev

    Tagir Valeev - 2015-02-17

    Please check with newest FindBugs version. If you still notice a problem, report a new bug providing the whole Java source file which produces a false-positive. Thanks.

     
    • vishal kharat

      vishal kharat - 2015-02-18

      Android studio does not install plugin FindBugs 3.0.0.
      While installing we get an error "Fail to load plugin descriptor from file findbugs-3.0.0.zip"

       

      Last edit: vishal kharat 2015-02-18
      • Andrey Loskutov

        Andrey Loskutov - 2015-02-18

        Android studio is not based on Eclipse, it is based on IntelliJ IDEA.
        We do not host or maintain FindBugs plugins for IDEA, please ask Google where the right project tracker for IDEA FindBugs plugin is - this one is wrong.

         
  • Tagir Valeev

    Tagir Valeev - 2015-02-18
    • status: closed-invalid --> open-invalid
     
  • Tagir Valeev

    Tagir Valeev - 2015-02-18

    Probably 0.9.994 was the reference to IDEA plugin version, not the FindBugs version. See:
    https://plugins.jetbrains.com/plugin/3847?pr=idea
    It integrates with FindBugs 3.0.0.

    Ok, I reopen it. But please provide the whole Java file where you observe this false-positive (simplify it as much as possible and remove all the external dependencies so we can compile it). Supplied code snippet is not enough for us to reproduce this problem.

     
  • Tagir Valeev

    Tagir Valeev - 2015-02-18

    By the way without reproducing I probably understand, what's the problem. You have System.out.println("Gets Called"); in your finally block before closing the stream. FindBugs thinks that this call may cause an exception and in this case your stream will not be closed. Having exception in System.out.println is possible (for example if you call System.setOut(null) somewhere else in your code or stack overflow occurs). You may either modify your code to use System.out after closing the stream or simply ignore this message if you're confident that System.out.println call will never throw an exception in your case.

     
  • William Pugh

    William Pugh - 2015-02-21

    I'm unable to reproduce this warning using the current version of FindBugs.

     
  • William Pugh

    William Pugh - 2015-02-21
    • status: open-invalid --> closed-works-for-me
     

Log in to post a comment.