android / android/codelab-android-paging

IllegalArgumentException: Additional prepend event after prepend state is done

Open
#124 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
509
Forks
268
PR merge metrics
No merged PRs in 30d

Description

with version "3.0.0-alpha08"

How to reproduce afaik:

with a PagingSource which can provide more elements than PagerConfig.maxSize,
1. scroll down more items than maxSize,
2. scroll up until a load needs to happen:

`java.lang.IllegalArgumentException: Additional prepend event after prepend state is done
at androidx.paging.SeparatorState.onInsert(Separators.kt:221)
at androidx.paging.SeparatorState.onEvent(Separators.kt:173)
at androidx.paging.SeparatorsKt$insertEventSeparators$$inlined$map$1$2.emit(Collect.kt:135)
at androidx.paging.PagingDataKt$map$$inlined$transform$1$2.emit(Collect.kt:136)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:58)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:11)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:185)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:108)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:308)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:395)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:872)
at kotlinx.coroutines.channels.ArrayChannel.offerInternal(ArrayChannel.kt:83)
at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:133)
at androidx.paging.PageFetcherSnapshot.doLoad(PageFetcherSnapshot.kt:487)
at androidx.paging.PageFetcherSnapshot$doLoad$1.invokeSuspend(Unknown Source:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
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)`

Is it possible to provide a CoroutineContext that catches these exceptions so the app does not crash but we can report them?

Workaround: setting `PagerConfig.maxSize = Int.MAX_VALUE` but it defeats the purpose of using the paging library for infinite lists.

Contributor guide

Open the contributing guide

Research direction

Start with Separators.kt around SeparatorState.onInsert and onEvent, then inspect the load path at PageFetcherSnapshot.kt:487. Reproduce using a PagingSource whose data exceeds PagerConfig.maxSize, scroll down past the limit, and scroll back up; done means the reported prepend failure is handled without the app crash or the underlying paging error is fixed.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.