On my EJB App (Java EE), I proceed a list (LinkedList) to insert into db and I got error: ArrayIndexOutOfBoundsException: -32443
I code as
Iterator itertator = myList.iterator();
while (itertator.hasNext()) {
MyObject myObject = (MyObject) itertator.next();
...
}
I wonder as I already use iterator.next why it could has indexOutOfBound?
Full log:
Error message: java.lang.ArrayIndexOutOfBoundsException: -32443; nested exception is: com.my.exception.MyException
at com.ibm.ejs.container.RemoteExceptionMappingStrategy.mapEJBException(RemoteExceptionMappingStrategy.java:411)
at com.ibm.ejs.container.RemoteExceptionMappingStrategy.mapException(RemoteExceptionMappingStrategy.java:113)
at com.ibm.ejs.container.RemoteExceptionMappingStrategy.setUncheckedException(RemoteExceptionMappingStrategy.java:203)
at com.ibm.ejs.container.EJSDeployedSupport.setUncheckedException(EJSDeployedSupport.java:296)
My EJB App is accessed by a Java client in multi-threading, the list is implemented in EJB itself by taking the id from the client to find data insert into a linkedlist and then send the list to insert by iterating as above, by randomly it got error.
Anyone could help to find the clue? Or the issue because I am using LinkedList, the size of the object is not enough?
I’d assume that the list isn’t thread safe. In case the list is accessed by a number of threads an an other thread accesses the last element at the moment, the
iterator.hasNext()is true. But when another thread does aiterator.next(), then you try to access the next element that isn’t available. The fact, that is error happens randomly is another hint for that. Using a thread safe list would be a good idea in this case. Otherwise manually synchronizing the list is necessary: