[FB-Discuss] My Bug or Bug in Findbugs ???

David Hovemeyer daveho at cs.umd.edu
Fri Dec 3 09:05:47 EST 2004


Hi Mathias,

Thanks for the feedback.

The bug detector which reports ODR warnings has a number of bugs,
and is due to be rewritten in the next month or two (as soon as
I can find some time :-)

-Dave

On Fri, Dec 03, 2004 at 02:35:17PM +0100, Schacht Mathias wrote:
> Hi,
> 
> i am currently checking some code of mine wiht findbugs and in the snipplet (attached at the end)
> i receive an findbugs message on the following line :
> ps = con.prepareStatement("select * from table");
> 
> The message is :
> ODR Exception :
> 
> Method may fail to close database resource on exception
> 
> The method creates a database resource (such as a database connection or row set), does not assign it to any fields, pass it to other methods, or return it, and does not appear to 
>  close the object on all exception paths out of the method. Failure to close database resources on all paths out of a method may result in poor performance, and could cause the 
>  application to have problems communicating with the database.
> 
> I cannot see, why i get this message and why i only get it for the PreparedStatement.
> Can anyone give me an hint, if this is really a bug in source or if findbugs cannot handle the code correctly.
> 
> Kind Regards
> Mathias
> 
> 
> public void showDatabaseContent() {
> 
> 	Connection con = null;
> 	ResultSet rs = null;
> 	PreparedStatement ps = null;			
> 	try {
> 		con = DataSource.getConnection(); // a JBoss Datasource
> 		ps = con.prepareStatement("select * from table");
> 		rs = ps.executeQuery();				
> 		while (rs.next()) {
> 			// evaluation of ResultSet;
> 		}
> 		rs.close();
> 		ps.close();
> 		con.close();
> 	} catch (Exception ex) {
> 		ex.printStackTrace();
> 	} finally {			
> 		if (rs != null) {
> 			try {
> 				rs.close();
> 			} catch (SQLException e) {
> 				e.printStackTrace();
> 			}
> 		}
> 		if (ps != null) {
> 			try {
> 				ps.close();
> 			} catch (SQLException e) {
> 				e.printStackTrace();
> 			}
> 		}
> 		if (con != null) {
> 			try {
> 				con.close();
> 			} catch (SQLException e) {
> 				e.printStackTrace();
> 			}
> 		}
> 	}
> }
> 
> 
> 
> 
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss at mimsy.cs.umd.edu
> http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss



More information about the Findbugs-discuss mailing list