I'm just a user, but I think I can explain this one. It appears that
FindBugs doesn't look down the call tree to see whether things get
closed in some method called from the finally block. If you want to
keep FB from complaining, you'll have to call stmt.close(), explicitly.
-blake
Mark Hillary wrote:
Hi All,
I have Database code that find bugs is reporting as a potential problem,
though I can't see anything wrong with it. The code follows this pattern
public void dropTestTable() {
Statement stmt = null;
try{
stmt = con.createStatement();
stmt.executeUpdate( "DROP TABLE TEST" );
}catch( SQLException e ) {
e.printStackTrace();
}finally{
SQLUtils.closeResources( stmt );
}
}
The SQLUtils.closeResources method is
public static void closeResources( Statement ... stmts ){
for( Statement stmt : stmts ){
try {
if( stmt != null )
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Findbugs is telling me that the method may fail to close the database
resource. Is there something obvious that I'm missing?
Thanks
Mark Hillary
------------------------------------------------------------------------
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@xxxxxxxxxxxxxxxxxx
http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
|