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

From Radu Buzila
Subject BUG #4598: flaw in hashCode() method implementation of Connection class in postgresql-8.3-604.jdbc3.jar
Date
Msg-id 200812302249.mBUMnXsv049575@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #4598: flaw in hashCode() method implementation of Connection class in postgresql-8.3-604.jdbc3.jar
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: Vincent Predoehl
Date:
Subject: Re: Bug
Next
From: "Lee McKeeman"
Date:
Subject: Re: Status of issue 4593