During automatic testing of my app in the simulator, occasionally (and quite rarely) I get errors like this:
[EDT] 0:24:35,723 - Exception: java.lang.IndexOutOfBoundsException - Index: 12, Size: 13
[EDT] 0:24:35,725 - Exception in MyApp version 2.0
[EDT] 0:24:35,725 - OS ios
[EDT] 0:24:35,725 - Error java.lang.IndexOutOfBoundsException: Index: 12, Size: 13
[EDT] 0:24:35,725 - Current Form Main
[EDT] 0:24:35,725 - Exception: java.lang.IndexOutOfBoundsException - Index: 12, Size: 13
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at com.codename1.ui.Container.paint(Container.java:1851)
at com.codename1.ui.Component.internalPaintImpl(Component.java:2279)
at com.codename1.ui.Component.paintInternalImpl(Component.java:2252)
at com.codename1.ui.Component.paintInternal(Component.java:2227)
at com.codename1.ui.Container.paintIntersecting(Container.java:1907)
at com.codename1.ui.Component.paintIntersectingComponentsAbove(Component.java:2312)
at com.codename1.ui.Component.internalPaintImpl(Component.java:2287)
at com.codename1.ui.Component.paintInternalImpl(Component.java:2252)
at com.codename1.ui.Component.paintInternal(Component.java:2227)
at com.codename1.ui.Component.paintInternal(Component.java:2195)
at com.codename1.ui.Component.paintComponent(Component.java:2492)
at com.codename1.ui.Component.paintComponent(Component.java:2436)
at com.codename1.impl.CodenameOneImplementation.paintDirty(CodenameOneImplementation.java:625)
at com.codename1.impl.javase.JavaSEPort.paintDirty(JavaSEPort.java:2247)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1286)
at com.codename1.ui.Display.mainEDTLoop(Display.java:1189)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
So it seems that paint is done concurrently with manipulation of an ArrayList of components (removing and adding elements). I have a background thread that simulates user input by calling functions that are normally triggered by pressing a button. All calls are wrapped in a callSerially.
I have been unable to reproduce this error by normal user input (pressing buttons), but still I want to be sure this cannot happen during normal use. So I would like to know what causes this and how to prevent it.