Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 405663

Summary: [compiler][resource] leak at re-assignment no longer detected
Product: [Eclipse Project] JDT Reporter: Stephan Herrmann <stephan.herrmann>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: tom.schindl
Version: 4.3Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Stephan Herrmann CLA 2013-04-13 03:59:11 EDT
The following leak is correctly detected up-to 4.3 M1 but not with M2+

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Bla {

    public static void bla(Connection c) {
        PreparedStatement stmt = null;
        try {
            stmt = c.prepareStatement("SELECT Bla"); // expect warning here
//            stmt.close();

            stmt = c.prepareStatement("SELECT Bli");
            stmt.close();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if( stmt != null ) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}

Note that this test requires a JRE 7+ to consider PreparedStatement as
a resource.
Comment 1 Stephan Herrmann CLA 2013-04-13 04:00:13 EDT
I'll try to fix this regression in time for Kepler.
Comment 2 Stephan Herrmann CLA 2013-04-13 04:18:30 EDT
Regression is caused by the fix for bug 388996.

Out-of-order analysis of finally before try block gets the analysis
confused here, or more precisely: attempts to cope with this out-of-order
analysis from bug 388996 are over eager.
Comment 3 Stephan Herrmann CLA 2013-04-30 08:52:53 EDT
I didn't find the time to fix this for Kepler.
Comment 4 Stephan Herrmann CLA 2014-04-12 09:16:23 EDT
Java 8 work had priority during 4.4, deferring to 4.5
Comment 5 Stephan Herrmann CLA 2016-03-25 10:30:56 EDT
Too much on my plate for 4.6. Bulk deferral to 4.7
Comment 6 Stephan Herrmann CLA 2017-05-16 12:05:35 EDT
Ran out of time for 4.7. Bulk move to 4.8.
Comment 7 Manoj N Palat CLA 2018-05-16 12:56:21 EDT
bulk move out of 4.8