ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

View: New views
3 Messages — Rating Filter:   Alert me  

ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

by Ulli Hafner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a question about the detector ODR_OPEN_DATABASE_RESOURCE in
findbugs 1.3.8. In the following snipped the detector creates a warning
with the message that the statement on line 97 is not closed. However,
the JDBC API defines that if a connection is closed than the connection
object should also close the associated statements. Shouldn't the
detector be adjusted to handle that case?

094         try {
095             connection = connect();
096
097             CallableStatement statement =
connection.prepareCall(query);
098             statement.execute();
099         }
100         catch (SQLException exception) {
101             throw new DatabaseException(exception);
102         }
103         finally {
104             close(connection);
105         }

Ulli

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

by Dave Brosius-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is true if the connection is a raw connection, however it's possible that the connection came from a pool, in which case close doesn't close a connection, it just allows the pool to reuse it. So in this case you do want to close all the statements as well. And i'd go further to say, you probably should close them yourself in all cases anyway, as you don't know for sure that the driver you use tomorrow will do the right thing.

-----Original Message-----
From: "Hafner Ullrich" <Ullrich.Hafner@...>
Sent: Wednesday, October 7, 2009 10:56am
To: Findbugs-discuss@...
Subject: [FB-Discuss] ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

Hi,

I have a question about the detector ODR_OPEN_DATABASE_RESOURCE in
findbugs 1.3.8. In the following snipped the detector creates a warning
with the message that the statement on line 97 is not closed. However,
the JDBC API defines that if a connection is closed than the connection
object should also close the associated statements. Shouldn't the
detector be adjusted to handle that case?

094 try {
095 connection = connect();
096
097 CallableStatement statement =
connection.prepareCall(query);
098 statement.execute();
099 }
100 catch (SQLException exception) {
101 throw new DatabaseException(exception);
102 }
103 finally {
104 close(connection);
105 }

Ulli

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Parent Message unknown Re: ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

by Dave Brosius-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

not that i am aware of.

-----Original Message-----
From: "Hafner Ullrich" <Ullrich.Hafner@...>
Sent: Wednesday, October 7, 2009 5:37pm
To: "Dave Brosius" <dbrosius@...>
Subject: RE: [FB-Discuss] ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

Hmm, the API description says:
 
"Closing a connection instance that was obtained from a pooled connection does not close the physical database connection. It does, however, free the resources of the connection instance, clear the state, close statement objects created from the connection instance, and restore the defaults for the next connection instance that will be created."
 
Is there a way to configure findbugs to only find missing close connection statements and not the other "missing" statements? I think it makes sense to trust the JDBC driver developers, otherwise you will produce a lot of redundant code:-) 
 
Ulli

From: Dave Brosius [mailto:dbrosius@...]
Sent: Mittwoch, 7. Oktober 2009 17:49
To: Findbugs-discuss@...
Cc: Hafner Ullrich
Subject: RE: [FB-Discuss] ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

This is true if the connection is a raw connection, however it's possible that the connection came from a pool, in which case close doesn't close a connection, it just allows the pool to reuse it. So in this case you do want to close all the statements as well. And i'd go further to say, you probably should close them yourself in all cases anyway, as you don't know for sure that the driver you use tomorrow will do the right thing.

-----Original Message-----
From: "Hafner Ullrich" <Ullrich.Hafner@...>
Sent: Wednesday, October 7, 2009 10:56am
To: Findbugs-discuss@...
Subject: [FB-Discuss] ODR_OPEN_DATABASE_RESOURCE in findbugs 1.3.8

Hi,

I have a question about the detector ODR_OPEN_DATABASE_RESOURCE in
findbugs 1.3.8. In the following snipped the detector creates a warning
with the message that the statement on line 97 is not closed. However,
the JDBC API defines that if a connection is closed than the connection
object should also close the associated statements. Shouldn't the
detector be adjusted to handle that case?

094 try {
095 connection = connect();
096
097 CallableStatement statement =
connection.prepareCall(query);
098 statement.execute();
099 }
100 catch (SQLException exception) {
101 throw new DatabaseException(exception);
102 }
103 finally {
104 close(connection);
105 }

Ulli

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss