1

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.

J-J
  • 419
  • 2
  • 12

1 Answers1

1

This could mean you have an EDT violation somewhere in the code. Make sure you run with the EDT violation detection tool in the simulator to try and stomp this out.

If this happens during animation try to switch your usage of revalidate() to revalidateWithAnimationSafety().

If neither of those helps try narrowing down the code that triggers this.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Yes I always run with full EDT debugging. But as you know it doesn't catch everything, so I put in a few assert isEdt()s and indeed I found an EDT violation in one thread and after fixing that no more exceptions occurred. Thanks! – J-J May 25 '21 at 12:32