From: | Florent Guillaume <fg(at)nuxeo(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | PGXAConnection ConnectionHandler equals bug |
Date: | 2011-10-17 17:01:04 |
Message-ID: | CAF-4BpPdTUVnZQd-Y70-uSHVUJ-hfxLmfCW+MBL1i1AEaLoPMg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hi,
When you have a Connection coming from a XAConnection, the equals()
method doesn't work: conn.equals(conn) returns false.
The reason is that it's a actually a wapper, a
org.postgresql.xa.PGXAConnection.ConnectionHandler, and its invoke()
method doesn't take into account the "equals" case to unwrap the
second argument as well if needed.
I observed this bug using the driver with Apache commons-dbcp and a XA
datasource factory.
FYI this is tracked in our code base as https://jira.nuxeo.com/browse/NXP-6985
Here's a unit test and patch for it.
Regards,
Florent
diff --git a/org/postgresql/test/xa/XADataSourceTest.java
b/org/postgresql/test/xa/XADataSourceTest.java
index ea316fb..6e8e300 100644
--- a/org/postgresql/test/xa/XADataSourceTest.java
+++ b/org/postgresql/test/xa/XADataSourceTest.java
@@ -130,6 +130,10 @@ public class XADataSourceTest extends TestCase {
}
}
+ public void testWrapper() throws Exception {
+ assertTrue("Wrappers should be equal", conn.equals(conn));
+ }
+
public void testOnePhase() throws Exception {
Xid xid = new CustomXid(1);
xaRes.start(xid, XAResource.TMNOFLAGS);
diff --git a/org/postgresql/xa/PGXAConnection.java
b/org/postgresql/xa/PGXAConnection.java
index ee84488..8386226 100644
--- a/org/postgresql/xa/PGXAConnection.java
+++ b/org/postgresql/xa/PGXAConnection.java
@@ -153,6 +153,16 @@ public class PGXAConnection extends
PGPooledConnection implements XAConnection,
}
}
try {
+ if (method.getName().equals("equals")) {
+ Object arg = args[0];
+ if (Proxy.isProxyClass(arg.getClass())) {
+ InvocationHandler h = Proxy.getInvocationHandler(arg);
+ if (h instanceof ConnectionHandler) {
+ // unwrap argument
+ args = new Object[] {
((ConnectionHandler) h).con };
+ }
+ }
+ }
return method.invoke(con, args);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
--
Florent Guillaume, Director of R&D, Nuxeo
Open Source, Java EE based, Enterprise Content Management (ECM)
http://www.nuxeo.com http://www.nuxeo.org +33 1 40 33 79 87
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2011-10-17 17:28:35 | Re: PGXAConnection ConnectionHandler equals bug |
Previous Message | Maciek Sakrejda | 2011-10-14 22:01:14 | Re: Moving to git |