From the workbench
Findbugs Resource-Tracking Plugin
Findbugs Plugin
Project overview
This project grew from a concrete JDBC resource-leak case encountered while using Findbugs in Eclipse. A method received a connection from a helper, used it and did not close it. The original report describes a case the existing analysis missed.
I built an add-on, AdvancedResourceTrackr, to address that reported scenario. The useful starting point is the ownership boundary: the connection is opened inside one method, but the caller receives and uses the resource.
The connection crosses a method boundary
In the original example, Test() calls getConn(), then creates a statement and executes a query. The helper returns DriverManager.getConnection(...). The cleanup block contains a commented-out conn.close(), so the connection is not released by that code.
That makes the helper call the important detail. Looking only for a direct connection-creation call in the consuming method would not describe this example. The add-on was written to recognise the leak situation reported there.
What is available to explore
- The original report includes the fuller JDBC example and explains the missed connection leak.
- The repository preserves the plugin project for inspection and further experimentation.
- The historical distribution is named LeakedResourceDetector.jar under AdvancedResourceTrackr/dist/.
Following the resource through the example
Historical leak scenario
Caller requests a connection
Test() invokes getConn().
Helper opens the resource
DriverManager creates the JDBC connection.
Caller uses the returned connection
Create a statement and execute a query.
Cleanup is omitted
The example's conn.close() is commented out.
The essential part of the report
These shortened excerpts preserve the helper-returned connection and omitted cleanup. They intentionally illustrate the historical leak, not recommended application code.
private static Connection getConn() throws SQLException {
return DriverManager.getConnection(DB_URL, USER, PASS);
}conn = getConn();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// In the original finally block, conn.close() is commented out.Project notes
This page documents a 2014 Findbugs/Eclipse project. It does not establish compatibility with current Findbugs or SpotBugs versions, or claim detection coverage beyond the reported scenario.