Bug 405569 - Resource leak check false positive when using DbUtils.closeQuietly
Summary: Resource leak check false positive when using DbUtils.closeQuietly
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.4 M1   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-12 09:36 EDT by James Clark CLA
Modified: 2013-08-06 20:59 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Clark CLA 2013-04-12 09:36:01 EDT
I believe I'm getting a false positive resource leak warning when resources are closed using apache dbutils closeQuietly methods.
Simplified Code:
public static void test(Connection con){ 
	PreparedStatement ps = null;
	try {
		ps = con.prepareStatement("foo");
		// Remove this loop for no warning 
		for (int i = 0; i < 1; i++) {
			try {
				ps.executeUpdate();
			} catch (SQLException e) {
				throw new SQLException("Some message", e); // << warning
			}
			// << move the closing finally to here for no warning
		}
	} catch (SQLException e) {
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(ps);  // << change this to ps.close for no warning
	}
}



The warning is removed if:
 1, I add the finally block after the inner try-catch
 2, I change closeQuietly to ps.close() (with the required try-catch wrapper)
 3, I remove the for-loop
Comment 1 Stephan Herrmann CLA 2013-04-12 11:25:10 EDT
It seems you missed the train on bug 381445 :)

Please see bug 381445 comment 11 for utilities which are known to the analysis.

It's amazing how many ppl implemented this one method closeQuietly ...
Comment 2 James Clark CLA 2013-04-12 11:52:29 EDT
Ah, I had seen that bug but had missed that the fix doesn't support other close* methods. Apologies.
Comment 3 Stephan Herrmann CLA 2013-07-09 13:53:19 EDT
I've added support for the following methods from org.apache.commons.dbutils.DbUtils:
- close(Connection conn)
- close(ResultSet rs)
- close(Statement stmt)
- closeQuietly(Connection conn)
- closeQuietly(Connection conn, Statement stmt, ResultSet rs)
- closeQuietly(ResultSet rs)
- closeQuietly(Statement stmt)
- commitAndClose(Connection conn)
- commitAndCloseQuietly(Connection conn)
- rollbackAndClose(Connection conn)
- rollbackAndCloseQuietly(Connection conn) 

Starting with JRE 1.7 all parameters are AutoCloseable (for 1.6 no leak analysis will
be performed for these types).

The 3-arg closeQuietely() is s.t. new: indeed all three arguments are AutoCloseable
and invocation of close() has to be recorded for all three.

Released for 4.4 M1 via commit c9c5f11eddd07d2a8299046a3df03585e022db6e.
Comment 4 Stephan Herrmann CLA 2013-07-09 13:54:51 EDT
resolved as per previous comment.
Comment 5 shankha banerjee CLA 2013-08-06 04:40:28 EDT
Nothing to verify. 

Verified for 4.4M1 using I20130805-0800 build.
Comment 6 Manoj N Palat CLA 2013-08-06 20:59:38 EDT
(In reply to comment #5)
> Nothing to verify. 
Verification done by checking for the presence of warning message in an earlier eclipse and the absence of warning message in the current version.

> 
> Verified for 4.4M1 using I20130805-0800 build.