Fixed
Status Update
Comments
su...@google.com <su...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
ru...@gmail.com <ru...@gmail.com> #3
yea i'll take it.
an...@google.com <an...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
ru...@gmail.com <ru...@gmail.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ra...@google.com <ra...@google.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
ru...@gmail.com <ru...@gmail.com> #7
yea sorry immediate does not fix it.
I actually have a WIP fix for it:
https://android-review.googlesource.com/c/platform/frameworks/support/+/1112186
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
Description
Version used: 2.1.0
Devices/Android versions reproduced on: 6.0
We're getting this crash on multiple devices:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.util.ArrayMap.containsKey(java.lang.Object)' on a null object reference
at android.os.BaseBundle.containsKey + 277(BaseBundle.java:277)
at androidx.work.impl.background.systemjob.SystemJobScheduler.getPendingJobIds + 331(SystemJobScheduler.java:331)
at androidx.work.impl.background.systemjob.SystemJobScheduler.schedule + 138(SystemJobScheduler.java:138)
at androidx.work.impl.Schedulers.schedule + 93(Schedulers.java:93)
at androidx.work.impl.WorkManagerImpl.rescheduleEligibleWork + 587(WorkManagerImpl.java:587)
at androidx.work.impl.utils.ForceStopRunnable.run + 82(ForceStopRunnable.java:82)
at androidx.work.impl.utils.SerialExecutor$Task.run + 75(SerialExecutor.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1113(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 588(ThreadPoolExecutor.java:588)
at java.lang.Thread.run + 833(Thread.java:833)
For some reason, the mMap in BaseBundle is null and getPendingJobIds doesn't catch that:
for (JobInfo jobInfo : jobs) {
PersistableBundle extras = jobInfo.getExtras();
// The map inside extras can be null, so extras.containsKey can cause a NPE
if (extras != null && extras.containsKey(EXTRA_WORK_SPEC_ID)) {
if (workSpecId.equals(extras.getString(EXTRA_WORK_SPEC_ID))) {
jobIds.add(jobInfo.getId());
}
}
}