BeksOmega / looping-layout

A looping LayoutManager for the Android RecyclerView.
Apache License 2.0
271 stars 16 forks source link

LoopingLayoutManager not restoring LayoutRequest from Parcel correctly #67

Open abcdefguan opened 2 years ago

abcdefguan commented 2 years ago

:bug: Describe

LayoutRequest doesn't correctly restore hasBeenInitialized correctly when parceled, then unparceled. When parceled again, it crashes to "LayoutRequest has not been initialized"

LoopingLayoutManager:1180 public constructor(parcel: Parcel) : this() { anchorIndex = parcel.readInt() scrollOffset = parcel.readInt() adapterDirection = parcel.readInt() } This code doesn't restore hasBeenInitialized unlike the other constructor. So if you restore it from the constructor above, then try to Parcel it again, hasBeenInitialized will be false and there will be a crash

You can fix this by adding hasBeenInitialized to the Parcel

:snail: Steps to reproduce

Create fragment X that has the looping layout manager Go to fragment Y that doesn't have the looping layout manager and startActivityForResult to activity Z. Hope that onSaveInstanceState triggers here Go back to fragment Y. Hope that onRestoreInstanceState triggers here Go back to activity Z. Crashes.

:butterfly: Expected behavior

No crash

:beetle: Other info

:bee: Requested assignment

I'm just reporting this problem. I don't want to fix it.

jonathanfontaine commented 1 year ago

Any news on this crash? I think I got the same issue (with version 0.5.0), found in Google Analytics :

Exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:581)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
Caused by java.lang.reflect.InvocationTargetException:
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
Caused by java.lang.Exception: LayoutRequest has not been initialized.
  at com.bekawestberg.loopinglayout.library.LoopingLayoutManager$LayoutRequest.getAnchorIndex (LoopingLayoutManager.kt)
  at com.bekawestberg.loopinglayout.library.LoopingLayoutManager$LayoutRequest.writeToParcel (LoopingLayoutManager.kt)
  at android.os.Parcel.writeParcelable (Parcel.java:2550)
  at androidx.recyclerview.widget.RecyclerView$SavedState.writeToParcel (RecyclerView.java)
  at android.os.Parcel.writeParcelable (Parcel.java:2550)
  at android.os.Parcel.writeValue (Parcel.java:2451)
  at android.os.Parcel.writeValue (Parcel.java:2328)
  at android.os.Parcel.writeSparseArray (Parcel.java:1434)
  at android.os.Parcel.writeValue (Parcel.java:2475)
  at android.os.Parcel.writeValue (Parcel.java:2328)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeTypedObject (Parcel.java:2169)
  at android.app.IActivityClientController$Stub$Proxy.activityStopped (IActivityClientController.java:1300)
  at android.app.ActivityClient.activityStopped (ActivityClient.java:85)
  at android.app.servertransaction.PendingTransactionActions$StopInfo.run (PendingTransactionActions.java:143)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8757)
qulj commented 4 months ago

Any news on this crash? I think I got the same issue (with version 0.5.0), found in Google Analytics :

Exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:581)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
Caused by java.lang.reflect.InvocationTargetException:
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
Caused by java.lang.Exception: LayoutRequest has not been initialized.
  at com.bekawestberg.loopinglayout.library.LoopingLayoutManager$LayoutRequest.getAnchorIndex (LoopingLayoutManager.kt)
  at com.bekawestberg.loopinglayout.library.LoopingLayoutManager$LayoutRequest.writeToParcel (LoopingLayoutManager.kt)
  at android.os.Parcel.writeParcelable (Parcel.java:2550)
  at androidx.recyclerview.widget.RecyclerView$SavedState.writeToParcel (RecyclerView.java)
  at android.os.Parcel.writeParcelable (Parcel.java:2550)
  at android.os.Parcel.writeValue (Parcel.java:2451)
  at android.os.Parcel.writeValue (Parcel.java:2328)
  at android.os.Parcel.writeSparseArray (Parcel.java:1434)
  at android.os.Parcel.writeValue (Parcel.java:2475)
  at android.os.Parcel.writeValue (Parcel.java:2328)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeBundle (Parcel.java:1346)
  at android.os.Parcel.writeValue (Parcel.java:2445)
  at android.os.Parcel.writeValue (Parcel.java:2335)
  at android.os.Parcel.writeArrayMapInternal (Parcel.java:1277)
  at android.os.BaseBundle.writeToParcelInner (BaseBundle.java:1802)
  at android.os.Bundle.writeToParcel (Bundle.java:1362)
  at android.os.Parcel.writeTypedObject (Parcel.java:2169)
  at android.app.IActivityClientController$Stub$Proxy.activityStopped (IActivityClientController.java:1300)
  at android.app.ActivityClient.activityStopped (ActivityClient.java:85)
  at android.app.servertransaction.PendingTransactionActions$StopInfo.run (PendingTransactionActions.java:143)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8757)

I also encountered the same problem, when can I solve it?