NPE from DBCP connection pool

3 messages Options
Embed this post
Permalink
TomStrummer

NPE from DBCP connection pool

Reply Threaded More More options
Print post
Permalink
Anyone ever seen this before?  A NPE from PoolingConnection.normalizeSQL:

java.lang.NullPointerException
        at org.apache.commons.dbcp.PoolingConnection.normalizeSQL(PoolingConnection.java:178)
        at org.apache.commons.dbcp.PoolingConnection.createKey(PoolingConnection.java:170)
        at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:92)
        at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
        at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
I've got a BasicDataSource and I'm trying to run a relatively simple query.  Not sure where the NPE could be coming from.  The SQL statement in question is extremely simple, a single-column SELECT with a single JOIN and a WHERE clause.  It works fine in a SQL browser.  The query is Oracle 11g, but I'm pretty sure that doesn't matter since it doesn't look like the query is getting that far.

Note that other queries still work, just this one in particular.  So it's not an issue with connections closing or something like that.  Any ideas?

Thanks.
-Tom
Niall Pemberton

Re: NPE from DBCP connection pool

Reply Threaded More More options
Print post
Permalink
On Thu, Oct 8, 2009 at 8:16 PM, TomStrummer <[hidden email]> wrote:

>
> Anyone ever seen this before?  A NPE from PoolingConnection.normalizeSQL:
>
>> java.lang.NullPointerException
>>         at
>> org.apache.commons.dbcp.PoolingConnection.normalizeSQL(PoolingConnection.java:178)
>>         at
>> org.apache.commons.dbcp.PoolingConnection.createKey(PoolingConnection.java:170)
>>         at
>> org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:92)
>>         at
>> org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
>>         at
>> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
>>
>
> I've got a BasicDataSource and I'm trying to run a relatively simple query.
> Not sure where the NPE could be coming from.  The SQL statement in question
> is extremely simple, a single-column SELECT with a single JOIN and a WHERE
> clause.  It works fine in a SQL browser.  The query is Oracle 11g, but I'm
> pretty sure that doesn't matter since it doesn't look like the query is
> getting that far.

The sql statement you're passing in has got to be null since the
normalizeSQL() method only does sql.trim(). Also it would make
investigation issues much easier if you specify the version of DBCP
you are using.

Niall

> Note that other queries still work, just this one in particular.  So it's
> not an issue with connections closing or something like that.  Any ideas?
>
> Thanks.
> -Tom
> --

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

TomStrummer

Re: NPE from DBCP connection pool

Reply Threaded More More options
Print post
Permalink
You're right; I looked at the DBCP source code and realized that my string was in fact null.  My fault.  

I'd suggest putting a guard and throw an IllegalArgumentException("SQL string cannot be null") to make it a little more clear that the NPE is in fact from the string argument, but it seems silly for something so trivial.  

Anyway, thank you for your prompt response.

-Tom


Niall Pemberton-2 wrote:
On Thu, Oct 8, 2009 at 8:16 PM, TomStrummer <tomstrummer@gmail.com> wrote:
>
> Anyone ever seen this before?  A NPE from PoolingConnection.normalizeSQL:
>
>> java.lang.NullPointerException
>>         at
>> org.apache.commons.dbcp.PoolingConnection.normalizeSQL(PoolingConnection.java:178)
>>         at
>> org.apache.commons.dbcp.PoolingConnection.createKey(PoolingConnection.java:170)
>>         at
>> org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:92)
>>         at
>> org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
>>         at
>> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
>>
>
> I've got a BasicDataSource and I'm trying to run a relatively simple query.
> Not sure where the NPE could be coming from.  The SQL statement in question
> is extremely simple, a single-column SELECT with a single JOIN and a WHERE
> clause.  It works fine in a SQL browser.  The query is Oracle 11g, but I'm
> pretty sure that doesn't matter since it doesn't look like the query is
> getting that far.

The sql statement you're passing in has got to be null since the
normalizeSQL() method only does sql.trim(). Also it would make
investigation issues much easier if you specify the version of DBCP
you are using.

Niall

> Note that other queries still work, just this one in particular.  So it's
> not an issue with connections closing or something like that.  Any ideas?
>
> Thanks.
> -Tom
> --

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org