users@glassfish.java.net

NullPointerException in AbstractResourcePool.isNonXAResourceInTransaction

From: <glassfish_at_javadesktop.org>
Date: Sat, 21 Jul 2007 14:06:44 PDT

I may have found a bug, but before I reported it I thought I ought to post here and make sure.

Background: Linux, Java 6u2, Glassfish v2-b56, I am porting an app from glassfish+hibernate to glassfish w/ builtin toplink.

If my transaction calls a createNativeQuery and getResultList or getSingleResult then the transaction fails when TopLink is doing its cleanup. If I use createQuery it is fine, or if I don't actually call the native query (not getSingleResult, or getResultList) everything is fine (although not very useful :-)).

I traced the call deep into the woods and found the trouble is in AbstractResourcePool:

private boolean isNonXAResourceInTransaction(J2EETransaction tran, ResourceHandle resource) {
    return resource.equals(tran.getNonXAResource());
}

Here tran is null. A simple fix would obviously be to check if tran is null before calling getNonXAResource (which would be a boolean), but I am not sure that this is not a symptom of a different problem i.e. the tran should not be null here.

It is called from:

    private boolean isLocalResourceInTransaction(ResourceHandle h) {
        boolean result = true;
               try{
                       J2EETransaction txn = (J2EETransaction)Switch.getSwitch().getTransactionManager().getTransaction();
                              result = isNonXAResourceInTransaction(txn,h);
               }catch(SystemException e){
                _logger.log(Level.FINE,"Exception while checking whether the resource is nonxa " +
                        "and is enlisted in transaction : ",e);
               }
        return result;
    }


Here the transactionManager's getTransaction returns a null.

This occurs whether I setup the connection pool as DataSource or XADataSource. The Connection is to a postgres database (8.1.9) using the postgresql jdbc driver 8.1-408-jdbc3

I hope this information is useful to someone to either help me out or solve the bug (and sorry about the poorly formatted code pasting).

Thanks,
Geoff
[Message sent by forum member 'gcruscoe' (gcruscoe)]

http://forums.java.net/jive/thread.jspa?messageID=227557