Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Juno - Spurious warning: Resource Leak
Juno - Spurious warning: Resource Leak [message #902109] Wed, 15 August 2012 17:42 Go to previous message
Jim Garrison is currently offline Jim Garrison
Messages: 5
Registered: August 2012
Junior Member
Resource leak: 'br' is not closed at this location [indicated below]

SSCCE:
import java.io.BufferedReader;
import java.io.FileReader;

public class LeakTest
{
    public int a;
    
    public void test() throws Exception
    {
        BufferedReader br = null;
        try
        {
            br = new BufferedReader(new FileReader("a.txt"));
            String line;
            while ((line=br.readLine()) != null)
            {
                System.out.println(line);
                if (a == 1)
                    throw new RuntimeException("X"); // <<<<<<<<<<<<==== HERE
            }
        }
        finally
        {
            if (br != null) try { br.close(); } catch(Exception e) { }
        }
    }
}


The warning is issued ONLY if the throw is part of an if/then (either branch) inside a loop. Remove the "if" or loop and the warning is not flagged.
 
Read Message
Read Message
Previous Topic:How to compile AST to bytecode
Next Topic:How can I use eclipse default package explorer to create my own package explorer
Goto Forum:
  


Current Time: Sat May 18 16:48:23 EDT 2013

Powered by FUDForum. Page generated in 0.01926 seconds