Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-3220

ARJUNA016009 ArrayIndexOutOfBoundsException during periodic recovery on EJBTransactionRecoveryService

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 8.1.0.CR1, 8.1.0.Final
    • 8.0.0.Final
    • EJB
    • None

      https://bugzilla.redhat.com/show_bug.cgi?id=1035216 is also reproducible in wildfly.

      WARN  [com.arjuna.ats.jta] (Periodic Recovery) ARJUNA016009: Caught:: java.lang.ArrayIndexOutOfBoundsException: 0
      	at org.jboss.as.ejb3.remote.EJBTransactionRecoveryService.getXAResources(EJBTransactionRecoveryService.java:114)
      	at com.arjuna.ats.internal.jbossatx.jta.XAResourceRecoveryHelperWrapper.getXAResources(XAResourceRecoveryHelperWrapper.java:51) [narayana-jts-integration-5.0.0.Final.jar:5.0.0.Final (revision: 9aa71)]
      	at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.resourceInitiatedRecoveryForRecoveryHelpers(XARecoveryModule.java:516) [narayana-jts-jacorb-5.0.0.Final.jar:5.0.0.Final (revision: 9aa71)]
      	at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.periodicWorkFirstPass(XARecoveryModule.java:182) [narayana-jts-jacorb-5.0.0.Final.jar:5.0.0.Final (revision: 9aa71)]
      	at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.doWorkInternal(PeriodicRecovery.java:743) [narayana-jts-jacorb-5.0.0.Final.jar:5.0.0.Final (revision: 9aa71)]
      	at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.run(PeriodicRecovery.java:371) [narayana-jts-jacorb-5.0.0.Final.jar:5.0.0.Final (revision: 9aa71)]
      

      I think the line 111 "new XAResource[receiverContexts.size()]" should be placed inside synchronized block.

      ejb3/src/main/java/org/jboss/as/ejb3/remote/EJBTransactionRecoveryService.java
      109     @Override
      110     public XAResource[] getXAResources() {
      111         final XAResource[] xaResources = new XAResource[receiverContexts.size()];
      112         synchronized (receiverContexts) {
      113             for (int i = 0; i < receiverContexts.size(); i++) {
      114                 xaResources[i] = EJBClientManagedTransactionContext.getEJBXAResourceForRecovery(receiverContexts.get(i), arjunaTxCoreEnvironmentBean.getValue().getNodeIdentifier());
      115             }
      116         }
      117         return xaResources;
      118     }
      ...
      124     @Override
      125     public void receiverRegistered(final EJBReceiverContext receiverContext) {
      126         this.receiverContexts.add(receiverContext);
      127     }
      

      I think this "java.lang.ArrayIndexOutOfBoundsException: 0" will happen in the following scenario:

      1. receiverContexts.size() = 0 at the line 111
        xaResources is created with new XAResource[0]
      2. receiverRegistered method is called from other thread between the line 111 and 112
        Now receiverContexts.size() = 1
      3. As receiverContexts.size() = 1, for-loop is executed
        Then "xaResources[0] = ..." will get ArrayIndexOutOfBoundsException at the line 114 because xaResources is empty array.

              rhn-support-mmiura Masafumi Miura
              rhn-support-mmiura Masafumi Miura
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: