java.lang.ArrayIndexOutOfBoundsException: 0

JBoss Issue Tracker | Masafumi Miura | 3 years ago
  1. 0

    https://bugzilla.redhat.com/show_bug.cgi?id=1035216 is also reproducible in wildfly. {code} 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)] {code} I think the line 111 "new XAResource\[receiverContexts.size()\]" should be placed inside synchronized block. {code:java|title=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 } {code} I think this "java.lang.ArrayIndexOutOfBoundsException: 0" will happen in the following scenario: # receiverContexts.size() = 0 at the line 111 xaResources is created with new XAResource\[0\] # receiverRegistered method is called from other thread between the line 111 and 112 Now receiverContexts.size() = 1 # As receiverContexts.size() = 1, for-loop is executed Then "xaResources\[0\] = ..." will get ArrayIndexOutOfBoundsException at the line 114 because xaResources is empty array.

    JBoss Issue Tracker | 3 years ago | Masafumi Miura
    java.lang.ArrayIndexOutOfBoundsException: 0
  2. 0

    https://bugzilla.redhat.com/show_bug.cgi?id=1035216 is also reproducible in wildfly. {code} 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)] {code} I think the line 111 "new XAResource\[receiverContexts.size()\]" should be placed inside synchronized block. {code:java|title=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 } {code} I think this "java.lang.ArrayIndexOutOfBoundsException: 0" will happen in the following scenario: # receiverContexts.size() = 0 at the line 111 xaResources is created with new XAResource\[0\] # receiverRegistered method is called from other thread between the line 111 and 112 Now receiverContexts.size() = 1 # As receiverContexts.size() = 1, for-loop is executed Then "xaResources\[0\] = ..." will get ArrayIndexOutOfBoundsException at the line 114 because xaResources is empty array.

    JBoss Issue Tracker | 3 years ago | Masafumi Miura
    java.lang.ArrayIndexOutOfBoundsException: 0
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Wildfly Jboss crashes with prepared transactions

    Stack Overflow | 2 years ago | abkvandrd
    XAException.XAER_RMERR: org.postgresql.xa.PGXAException: Error rolling back prepared transaction

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ArrayIndexOutOfBoundsException

      0

      at org.jboss.as.ejb3.remote.EJBTransactionRecoveryService.getXAResources()
    2. JBoss Application Server: EJB Subsystem
      EJBTransactionRecoveryService.getXAResources
      1. org.jboss.as.ejb3.remote.EJBTransactionRecoveryService.getXAResources(EJBTransactionRecoveryService.java:114)
      1 frame
    3. Narayana: ArjunaJTS integration
      XAResourceRecoveryHelperWrapper.getXAResources
      1. 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)]
      1 frame
    4. JBossTS jbossjta
      PeriodicRecovery.run
      1. 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)]
      2. 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)]
      3. 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)]
      4. 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)]
      4 frames