Subject Two XA bugs
Author Ludovic Orban
Hi,

I identified a bug in the way FBConnectionPoolDataSource manages
java.sql.Connection objects.

If you create a FBConnectionPoolDataSource and switch off pooling
using FBConnectionPoolDataSource.setPooling(false) and then you try
executing this code:


XAConnection xaConnection = fbDataSource.getXAConnection();
XAResource xaResource = xaConnection.getXAResource();

Xid xid = genXid();

Connection connection = xaConnection.getConnection();
xaResource.start(xid, XAResource.TMNOFLAGS);
xaResource.end(xid, XAResource.TMSUCCESS);
connection.close();

xaResource.prepare(xid);


the prepare() call will fail throwing a NPE:

java.lang.NullPointerException
at
org.firebirdsql.jca.FBManagedConnection.internalPrepare(FBManagedConnection.java:736)
at
org.firebirdsql.jca.FBManagedConnectionFactory.notifyPrepare(FBManagedConnectionFactory.java:613)
at
org.firebirdsql.jca.FBManagedConnection.prepare(FBManagedConnection.java:724)
at whatever.XATestSuite.testConnectionWrapper(XATestSuite.java:167)
...

Setting pooling to true fixes this issue. It looks like the problem
comes from the fact that calling connection.close() closes the
physical database connection which is incorrect. Only the call to
xaConnection.close() should do that which is what is done even when
pooling is set to true. That makes me wonder what that pooling
parameter is about.


Another quick & easy one:

XAConnection xaConnection = fbDataSource.getXAConnection();
XAResource xaResource = xaConnection.getXAResource();
xaConnection.close();
xaResource.recover(XAResource.TMSTARTRSCAN);

fails with NPE:

java.lang.NullPointerException
at
org.firebirdsql.jca.FBManagedConnection.recover(FBManagedConnection.java:792)
at
whatever.XATestSuite.testClosedXAResource(FbTest.java:35)
...

In this case, the driver misses a null check that should throw
XAException with XAER_RMFAIL.

Thanks in advance,
Ludovic