RaiMan / SikuliX-2014

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

Finder without results can't be easily destroyed #256

Closed ubershy closed 7 years ago

ubershy commented 7 years ago

Hello.

I use sikulixapi as java library. If a Finder instance does not have results yet, it's hard to clean it.

For example, the following code throws NullPointerException:

Finder finder = new Finder();
finder.destroy();

The culpit is this line (the link refers to the latest commit): https://github.com/RaiMan/SikuliX-2014/blob/dd9bc05710fffb1280b7746e4b3c11bc726940dd/API/src/main/java/org/sikuli/script/Finder.java#L139

What makes the situation a bit worse is that destroy() method is used in Finder.finalize(): https://github.com/RaiMan/SikuliX-2014/blob/dd9bc05710fffb1280b7746e4b3c11bc726940dd/API/src/main/java/org/sikuli/script/Finder.java#L153

Possible solution

Add a simple check that checks _results for null before running _results.delete() in Finder.destroy() method.

RaiMan commented 7 years ago

Thanks for finding. fixed 1.1.2 (2017-05-09, Travis build 37)