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

IndexOutOfBoundsException causing a lot of crashes #321

Closed
mohakapt opened this issue Jul 6, 2021 · 18 comments
Closed

IndexOutOfBoundsException causing a lot of crashes #321

mohakapt opened this issue Jul 6, 2021 · 18 comments

Comments

@mohakapt
Copy link

mohakapt commented Jul 6, 2021

I'm using this library in my application, recently i started to receive a large amount of crash reports from my users. I cannot reproduce the issue while debugging.
I'm using the latest version of the library.

com.kizitonwose.calendarview.ui.CalendarAdapter.notifyMonthScrollListenerIfNeeded (CalendarAdapter.kt:197)
com.kizitonwose.calendarview.ui.CalendarAdapter$notifyMonthScrollListenerIfNeeded$1.onAnimationsFinished (CalendarAdapter.kt:191)
androidx.recyclerview.widget.RecyclerView$ItemAnimator.dispatchAnimationsFinished (RecyclerView.java:13751)
androidx.recyclerview.widget.DefaultItemAnimator.dispatchFinishedWhenDone (DefaultItemAnimator.java:551)
androidx.recyclerview.widget.DefaultItemAnimator$5.onAnimationEnd (DefaultItemAnimator.java:249)
android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd (ViewPropertyAnimator.java:1111)
android.animation.Animator$AnimatorListener.onAnimationEnd (Animator.java:554)
android.animation.ValueAnimator.endAnimation (ValueAnimator.java:1242)
android.animation.ValueAnimator.cancel (ValueAnimator.java:1127)
android.view.ViewPropertyAnimator.cancel (ViewPropertyAnimator.java:424)
androidx.recyclerview.widget.DefaultItemAnimator.cancelAll (DefaultItemAnimator.java:642)
androidx.recyclerview.widget.DefaultItemAnimator.endAnimations (DefaultItemAnimator.java:634)
androidx.recyclerview.widget.RecyclerView.removeAndRecycleViews (RecyclerView.java:1205)
androidx.recyclerview.widget.RecyclerView.setAdapterInternal (RecyclerView.java:1236)
androidx.recyclerview.widget.RecyclerView.setAdapter (RecyclerView.java:1194)
com.kizitonwose.calendarview.CalendarView.invalidateViewHolders (CalendarView.kt:411)
com.kizitonwose.calendarview.CalendarView.onMeasure (CalendarView.kt:300)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1552)
android.widget.LinearLayout.measureVertical (LinearLayout.java:842)
android.widget.LinearLayout.onMeasure (LinearLayout.java:721)
android.view.View.measure (View.java:26415)
androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure (ConstraintLayout.java:811)
androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measure (BasicMeasure.java:466)
androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measureChildren (BasicMeasure.java:134)
androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solverMeasure (BasicMeasure.java:278)
androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure (ConstraintWidgetContainer.java:120)
androidx.constraintlayout.widget.ConstraintLayout.resolveSystem (ConstraintLayout.java:1593)
androidx.constraintlayout.widget.ConstraintLayout.onMeasure (ConstraintLayout.java:1700)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild (CoordinatorLayout.java:760)
com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild (HeaderScrollingViewBehavior.java:99)
com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild (AppBarLayout.java:2003)
androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure (CoordinatorLayout.java:831)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
androidx.appcompat.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:145)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1552)
android.widget.LinearLayout.measureVertical (LinearLayout.java:842)
android.widget.LinearLayout.onMeasure (LinearLayout.java:721)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1552)
android.widget.LinearLayout.measureVertical (LinearLayout.java:842)
android.widget.LinearLayout.onMeasure (LinearLayout.java:721)
android.view.View.measure (View.java:26415)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7845)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
com.android.internal.policy.DecorView.onMeasure (DecorView.java:1013)
android.view.View.measure (View.java:26415)
android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:3606)
android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:2349)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2641)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2201)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:9000)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:996)
android.view.Choreographer.doCallbacks (Choreographer.java:794)
android.view.Choreographer.doFrame (Choreographer.java:729)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:981)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:237)
android.app.ActivityThread.main (ActivityThread.java:7948)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075) 
@danieldcoded
Copy link

Do you have the source code available? Might be able to help you

@mohakapt
Copy link
Author

Are you referring to my source code? or the library's?
The crash is happening here CalendarAdapter.kt

@danieldcoded
Copy link

Sorry I just got to see this, I was referring to your source code. Or are you working on a private project?

@mohakapt
Copy link
Author

mohakapt commented Aug 8, 2021

Sorry for the late reply, I'm working on a private project so unfortunately I cannot share the source code.
The main issue here is that the stack trace doesn't refer to any code in my project so I'm not able to pinpoint what's starting the stack that's causing the crash.

@kizitonwose
Copy link
Owner

Just curious, do you use the month-to-week collapsing feature?

@mohakapt
Copy link
Author

Hello! Yes, I'm using that feature

@HoLuong1609
Copy link

I have a clue for this and raise a detail issue at #343

@olegsvs
Copy link

olegsvs commented Oct 13, 2021

@kizitonwose This happens if you go to for example to another fragment during the expansion animation (initial STATE_COLLAPSED) CalendarView, and go back to the screen with CalendarView (for reproduce, you can set a longer animation duration in the developer settings). In my case onRestoreInstanceState setting up saved STATE(collapsed/etc)

2021-10-14 01:20:44.191 11292-11292/com.* I/System.out: expandInternal to 2021-10 NO ANIM
2021-10-14 01:20:44.193 11292-11292/com.* I/System.out: STATE_EXPANDED
2021-10-14 01:20:44.193 11292-11292/com.* D/AndroidRuntime: Shutting down VM
2021-10-14 01:20:44.194 11292-11292/com.* E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.*, PID: 11292
    java.lang.IndexOutOfBoundsException: Index: 93, Size: 28
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.notifyMonthScrollListenerIfNeeded(CalendarAdapter.kt:197)
        at com.kizitonwose.calendarview.ui.CalendarAdapter$onAttachedToRecyclerView$1.run(CalendarAdapter.kt:59)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@kizitonwose
Copy link
Owner

kizitonwose commented Oct 14, 2021

@olegsvs So to reproduce with the Sample app:

  • Increase anim duration.
  • Toggle expanded state.
  • Navigate away from the page.

Is this correct?

@olegsvs
Copy link

olegsvs commented Oct 15, 2021

@kizitonwose Correct, i will try to reproduce on a sample and provide a project

@kizitonwose
Copy link
Owner

@olegsvs Thanks, that would be very helpful.

@olegsvs
Copy link

olegsvs commented Oct 21, 2021

@kizitonwose Sorry, I found a bug in my code, i used save and restore the status (week mode) of the calendar in onSaveState / onRestoreState, which entailed a double function call to expandCalendarView. I think the author of Issue also needs to give more details about the setup week mode in his project(wait for animation and block actions before anim has end). @mohakapt

@kizitonwose
Copy link
Owner

@olegsvs So the expand/collapse logic works fine otherwise?

@olegsvs
Copy link

olegsvs commented Oct 23, 2021

@kizitonwose Yep, I no longer had problems with multiple state changes or changing screens during animation, as I said, in problematic projects need to check the animation code for a change in height at the end of which there is a change in the calendar state, if animation is used. I think the creators of such Issue need to attach a code for changing the state of the weekMode

@olegsvs
Copy link

olegsvs commented Oct 23, 2021

@mohakapt
Copy link
Author

Hello, I checked my code but couldn't find anything different from the sample in this project. I'm setting up the calendar view exactly like the example here Example1Fragment.kt.

Personally, I couldn't reproduce the issue myself, on my devices the component wouldn't crash no matter what I do. The issue is only appearing on my Crashlytics reports from real users.

As a workaround I'm calling the setup() function on the calendar view every time the user switches between week and month views. It seems to work since the crash reports stopped appearing.

@kizitonwose
Copy link
Owner

A temporary workaround that I see would be to use getOrNull() instead of just accessing the index. However, I am trying to see if we can first get to the root of the issue, otherwise, this only suppresses the real problem.

@kizitonwose
Copy link
Owner

This is now fixed in version 2.0.0

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

No branches or pull requests

5 participants