geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1673231 - in /geronimo/components/txmanager/trunk/geronimo-transaction/src: main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
Date Mon, 13 Apr 2015 15:53:49 GMT
Author: gnodet
Date: Mon Apr 13 15:53:49 2015
New Revision: 1673231

URL: http://svn.apache.org/r1673231
Log:
[GERONIMO-6541] NPE during XAResource recovery with invalid Xids

Modified:
    geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
    geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java?rev=1673231&r1=1673230&r2=1673231&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
Mon Apr 13 15:53:49 2015
@@ -99,7 +99,11 @@ public class RecoveryImpl implements Rec
         Xid[] prepared = xaResource.recover(XAResource.TMSTARTRSCAN + XAResource.TMENDRSCAN);
         for (int i = 0; prepared != null && i < prepared.length; i++) {
             Xid xid = prepared[i];
-            log.trace("considering recovered xid from\n name: " + xaResource.getName() +
"\n " + toString(xid));
+            if (xid.getGlobalTransactionId() == null || xid.getBranchQualifier() == null)
{
+                log.warn("Ignoring bad xid from\n name: " + xaResource.getName() + "\n "
+ toString(xid));
+                continue;
+            }
+            log.trace("Considering recovered xid from\n name: " + xaResource.getName() +
"\n " + toString(xid));
             ByteArrayWrapper globalIdWrapper = new ByteArrayWrapper(xid.getGlobalTransactionId());
             XidBranchesPair xidNamesPair = ourXids.get(globalIdWrapper);
             
@@ -226,17 +230,24 @@ public class RecoveryImpl implements Rec
         StringBuilder s = new StringBuilder();
         s.append("[Xid:class=").append(xid.getClass().getSimpleName()).append(":globalId=");
         byte[] globalId = xid.getGlobalTransactionId();
-        for (int i = 0; i < globalId.length; i++) {
-            s.append(Integer.toHexString(globalId[i]));
+        if (globalId == null) {
+            s.append("null");
+        } else {
+            for (int i = 0; i < globalId.length; i++) {
+                s.append(Integer.toHexString(globalId[i]));
+            }
+            s.append(",length=").append(globalId.length);
         }
-        s.append(",length=").append(globalId.length);
         s.append(",branchId=");
         byte[] branchId = xid.getBranchQualifier();
-        for (int i = 0; i < branchId.length; i++) {
-            s.append(Integer.toHexString(branchId[i]));
+        if (branchId == null) {
+            s.append("null");
+        } else {
+            for (int i = 0; i < branchId.length; i++) {
+                s.append(Integer.toHexString(branchId[i]));
+            }
+            s.append(",length=").append(branchId.length);
         }
-        s.append(",length=");
-        s.append(branchId.length);
         s.append("]");
         return s.toString();
     }

Modified: geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java?rev=1673231&r1=1673230&r2=1673231&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-transaction/src/test/java/org/apache/geronimo/transaction/manager/RecoveryTest.java
Mon Apr 13 15:53:49 2015
@@ -99,6 +99,67 @@ public class RecoveryTest extends TestCa
 
     }
 
+    public void testInvalidXid() throws Exception {
+        final Xid[] xids = new Xid[] { new Xid() {
+            @Override
+            public int getFormatId() {
+                return 0;
+            }
+            @Override
+            public byte[] getGlobalTransactionId() {
+                return null;
+            }
+            @Override
+            public byte[] getBranchQualifier() {
+                return new byte[0];
+            }
+        } };
+        final NamedXAResource xares = new NamedXAResource() {
+            @Override
+            public String getName() {
+                return RM1;
+            }
+            @Override
+            public void commit(Xid xid, boolean b) throws XAException {
+            }
+            @Override
+            public void end(Xid xid, int i) throws XAException {
+            }
+            @Override
+            public void forget(Xid xid) throws XAException {
+            }
+            @Override
+            public int getTransactionTimeout() throws XAException {
+                return 0;
+            }
+            @Override
+            public boolean isSameRM(XAResource xaResource) throws XAException {
+                return false;
+            }
+            @Override
+            public int prepare(Xid xid) throws XAException {
+                return 0;
+            }
+            @Override
+            public Xid[] recover(int i) throws XAException {
+                return xids;
+            }
+            @Override
+            public void rollback(Xid xid) throws XAException {
+            }
+            @Override
+            public boolean setTransactionTimeout(int i) throws XAException {
+                return false;
+            }
+            @Override
+            public void start(Xid xid, int i) throws XAException {
+            }
+        };
+        prepareForReplay();
+        Recovery recovery = txManager.recovery;
+        recovery.recoverResourceManager(xares);
+    }
+
     private void addBranch(MockTransactionInfo[] txInfos, MockXAResource xaRes) throws XAException
{
         for (int i = 0; i < txInfos.length; i++) {
             MockTransactionInfo txInfo = txInfos[i];



Mime
View raw message