Thread: BUG #4598: flaw in hashCode() method implementation of Connection class in postgresql-8.3-604.jdbc3.jar

The following bug has been logged online:

Bug reference:      4598
Logged by:          Radu Buzila
Email address:      radu@buzila.com
PostgreSQL version: 8.3
Operating system:   Mac OS X (OS not relevant, I'm using the thin JDBC
driver: postgresql-8.3-604.jdbc3.jar)
Description:        flaw in hashCode() method implementation of Connection
class in postgresql-8.3-604.jdbc3.jar
Details:

This issue occurs when using the 8.3 thin driver
(postgresql-8.3-604.jdbc3.jar):
I have a hash that uses connection objects as keys (the hash keeps some some
transaction state data). Adding to the hash works fine but when checking if
the hash has a certain key a null pointer exception is thrown. The key used
is a not-null Connection object
(org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection) and the hash is
not empty.

A printout of the hash looks like this:
{Pooled connection wrapping physical connection null=[], Pooled connection
wrapping physical connection null=[], Pooled connection wrapping physical
connection null=[]}
(my hash values are empty ArrayList objects (not null) at this point and the
keys are Connection objects).

When executing either
theHash.containsKey(someKey)
or
theHash.remove(someKey)
(where someKey is an instance of
org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection) a
NullPoinerException is thrown and the stack trace shows:
... at
org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$ConnectionHandler.in
voke(AbstractJdbc23PooledConnection.java:275)
    at $Proxy0.hashCode(Unknown Source)
...

My immediate guess is that the method overriding Object.hashCode() is not
implemented properly and it throws a null pointer exception either in all
cases or only when the physical connection wrapped by the pooled connection
object is closed.
On Tue, 30 Dec 2008, Radu Buzila wrote:

>
> The following bug has been logged online:
>
> Bug reference:      4598
> driver: postgresql-8.3-604.jdbc3.jar)
> Description:        flaw in hashCode() method implementation of Connection
> class in postgresql-8.3-604.jdbc3.jar
> Details:
>
> [Pooled connections' hashCode method doesn't work after the connection
>  is closed failing with a NullPointerException]

Fixed in CVS.

Kris Jurka