RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 234 forks source link

IndexOutOfBoundsException in Region.findBest() method #255

Closed ubershy closed 7 years ago

ubershy commented 7 years ago

Hello.

Problem

I use Region.findBest(Object... args) method and pass target images as args. Everything is working good when target images exist on the screen, but when not, this method throws an exception:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[na:1.8.0_101] at java.util.ArrayList.get(ArrayList.java:429) ~[na:1.8.0_101] at org.sikuli.script.Region.findBest(Region.java:2549) ~[sikulixapi-1.1.1-SNAPSHOT.jar:na]

The Region.java:2549 line is: mResult = mList.get(0);

I'm using sikulixapi-1.1.1-SNAPSHOT as java library, but as I see the problem exists also in latest sikulixapi minor versions.

Possible solutions

  1. Add a list size check to findBest(Object... args) method to return null in this case. Or...
  2. Return null instead of empty list in the private findAnyCollect(Object... args) method which findBest(Object... args) method uses.
RaiMan commented 7 years ago

Thanks for finding. Fixed in 1.1.2-SNAPSHOT after 2017-05-08

ubershy commented 7 years ago

Thank you! =)