GERONIMO-4438 - TransactionSynchronizationRegistry.getTransactionKey should return null when transaction is not associated with the current thread

git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/txmanager/trunk@722724 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java b/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
index 1a0f324..59309de 100644
--- a/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
+++ b/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
@@ -205,8 +205,8 @@
     }
 
     public Object getTransactionKey() {
-        TransactionImpl tx = getActiveTransactionImpl();
-        return tx.getTransactionKey();
+    	TransactionImpl tx = (TransactionImpl) getTransaction();
+        return tx == null ? null: tx.getTransactionKey();
     }
 
     public int getTransactionStatus() {
diff --git a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
index 0b311a5..46b9355 100644
--- a/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
+++ b/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/TransactionSynchronizationRegistryTest.java
@@ -57,6 +57,15 @@
         tm.getTransaction().registerSynchronization(normalSync);
     }
 
+    public void testTransactionKey() throws Exception {
+    	normalSync = new CountingSync();
+    	assertNull(tm.getTransactionKey());
+    	setUpInterposedSync();
+    	tm.getTransaction().registerSynchronization(normalSync);
+    	assertNotNull(tm.getTransactionKey());
+    	tm.commit();
+    	assertNull(tm.getTransactionKey());
+    }
 
     public void testInterposedSynchIsCalledOnCommit() throws Exception {
         setUpInterposedSync();