Skip to main content

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 21:42 Go to next message
Jim Garrison is currently offline Jim GarrisonFriend
Messages: 5
Registered: August 2012
Junior Member
Resource leak: 'br' is not closed at this location [indicated below]


public class LeakTest
    public int a;
    public void test() throws Exception
        BufferedReader br = null;
            br = new BufferedReader(new FileReader("a.txt"));
            String line;
            while ((line=br.readLine()) != null)
                if (a == 1)
                    throw new RuntimeException("X"); // <<<<<<<<<<<<==== HERE
            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.
Re: Juno - Spurious warning: Resource Leak [message #902112 is a reply to message #902109] Wed, 15 August 2012 22:17 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1830
Registered: July 2009
Senior Member
We have a group of related bug reports already, for closest resemblance see

Common theme: the JLS specifies flow analysis for definite assignment across try statements in a very conservative manner. JDT re-uses the same flow analysis for analysis of null pointers access and resource leaks yielding results that are less precise than we would like.

I have hopes that after the fix in has been released most of these "bugs" can be resolve quite easily.

Until then please refer to f. for some advice how the code can be made easier to analyse for the compiler, notably by using the Java 7 construct try-with-resources!

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: Fri Jan 15 15:45:23 GMT 2021

Powered by FUDForum. Page generated in 0.01976 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top