I think this can be regarded as a false-positive.
51 public void execute(final String query) {
52 try (Connection conn = pool.getDatabaseConnection();
53 Statement stmt = conn.createStatement();) {
54 stmt.execute(query);
55 } catch (SQLException ex) {
56 logSQLException(ex);
57 }
58 }
generates:
[INFO] com.mycompany.db.Database.execute(String) may fail to clean up java.sql.Statement [com.mycompany.db.Database, com.mycompany.db.Database, com.mycompany.db.Database, com.mycompany.db.Database, com.mycompany.db.Database, com.mycompany.db.Database] Obligation to clean up resource created at Database.java:[line 53] is not dischargedPath continues at Database.java:[line 52]Path continues at Database.java:[line 54]Path continues at Database.java:[line 55]Path continues at Database.java:[line 57]Path continues at Database.java:[line 58] OBL_UNSATISFIED_OBLIGATION
I'm also seeing this on Java 8 with code like:
public static MyObject forId(long myObjectId, Connection cxn) throws SQLException {
try (PreparedStatement stmt = cxn.prepareStatement(selectMyObjectById))) {
stmt.setLong(1, myObjectId);
try (ResultSet res = stmt.executeQuery()) {
res.next();
return MyObject.fromResultSet(res);
where the JDBC Connection object is passed (but created with try-with-resources itself).
Is there any hope for this? I hate to scatter annotations to ignore this but I'd like to use the resource leak detector.