Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing zero targets leads to ArrayIndexOutOfBoundsException #84

Closed
Ynnck123 opened this issue Jan 19, 2020 · 2 comments
Closed

Showing zero targets leads to ArrayIndexOutOfBoundsException #84

Ynnck123 opened this issue Jan 19, 2020 · 2 comments

Comments

@Ynnck123
Copy link

If you build a Spotlight with an empty list of targets and afterwards call start(), it will lead to the following ArrayIndexOutOfBoundsException exception:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at com.takusemba.spotlight.Spotlight.showTarget(Spotlight.kt:94) at com.takusemba.spotlight.Spotlight.access$showTarget(Spotlight.kt:21) at com.takusemba.spotlight.Spotlight$startSpotlight$1.onAnimationEnd(Spotlight.kt:84) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1242) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1484) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146) at android.animation.AnimationHandler.access$100(AnimationHandler.java:37) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:964) at android.view.Choreographer.doCallbacks(Choreographer.java:790) at android.view.Choreographer.doFrame(Choreographer.java:721) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

I recommend adding a proper exception when you try to start the spotlight with an empty list or just check if the targets array is not empty before accessing it at line 94 in Spotlight class.

@TakuSemba
Copy link
Owner

Hi, thank you for reporting the issue.
Since Spotlight is not expecting empty targets, I want you to check if it's empty before adding to Spotlight.
Instead of taking care of empty targets case, I would check if it's empty or not when targets are added then throw an exception if it's empty.

I will release this fix on the next version.
Again, thank you for reporting.

@TakuSemba
Copy link
Owner

I fixed it on v2.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants