db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Noll <dan...@nuix.com>
Subject Re: NPE getting length of Blob
Date Wed, 05 Mar 2008 00:36:42 GMT
On Tuesday 04 March 2008 22:36:17 Narayanan wrote:
> I have tried getting a blob from a result set and tried the length()
> method on it after the following Scenarios
>
> 1) Closing the connection

The underlying problem must be something to do with Connection reuse.  We 
discovered that am.PreparedStatement.parameterMetaData_ was being set to null 
in markClosed(), and yet the same PreparedStatement object was being reused 
for subsequent blob length queries.  So it would work once and then not for 
any subsequent attempts.  Subsequent attempts for the same blob would 
probably work because the result is cached elsewhere but attempts for a 
different blob would use the same cached, invalid PreparedStatement object.

Here's who's setting it to null:
	at 
org.apache.derby.client.am.PreparedStatement.markClosed(PreparedStatement.java:2526);
	at org.apache.derby.client.am.Statement.markClosed(Statement.java:1755)
	at 
org.apache.derby.client.am.Connection.markStatementsClosed(Connection.java:879)
	at org.apache.derby.client.am.Connection.markClosed(Connection.java:864)
	at 
org.apache.derby.client.am.Connection.markClosedForReuse(Connection.java:872)
	at org.apache.derby.client.am.Connection.closeForReuse(Connection.java:833)
	at 
org.apache.derby.client.am.NetConnection.closeForReuse(NetConnection.java:1829)
	at 
org.apache.derby.client.am.LogicalConnection.close(LogicalConnection.java:80)

We're calling Connection.close() but it's a connection from a pool, and you're 
supposed to close those.

Potential fixes:
  - Don't set things to null during close methods (it's inherently dangerous.)
  - Check if the statement is closed after checking whether it's null 
(possibly defeats the purpose of caching the statement for the connection.)

Anyway now that we know roughly where the problem is, some Derby developer 
will presumably know better than us how to fix it without breaking anything 
else.

Daniel

Mime
View raw message