Fixed
Status Update
Comments
co...@protonmail.com <co...@protonmail.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
ch...@google.com <ch...@google.com> #3
yea i'll take it.
tn...@google.com <tn...@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.
co...@protonmail.com <co...@protonmail.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()
}
}
co...@protonmail.com <co...@protonmail.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)
tn...@google.com <tn...@google.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} )
}
il...@google.com <il...@google.com> #8
Project: platform/frameworks/support
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
https://android-review.googlesource.com/1112186
https://goto.google.com/android-sha1/af12e75e6b4110f48e44ca121466943909de8f06
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
co...@protonmail.com <co...@protonmail.com> #9
I don't have a sample project, but the error points to this file seemingly?
package com.rollertoaster.app
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
val MY_DISPATCHER: Dispatcher =
object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return MockResponse().setResponseCode(404)
}
}
Some more info here:
But besides that I don't have a repo that shows this publicly available.
co...@protonmail.com <co...@protonmail.com> #10
This is an unrelated issue, but Tor says "Methods aren't guaranteed to have a surrounding class so probably safest to use the ?. operator..." and so maybe that's what has to be done in this lint check as well?
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #11
Project: platform/frameworks/support
Branch: androidx-main
commit 0a9efa914d322810f8dc8d9ba06e79d164c8892d
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Jun 09 13:01:36 2021
Fix lint crashes on kotlin top level properties
We need to handle cases where kotlin functions don't have a surrounding
class.
This change allows the surrounding class to be null and in that case we
just skip the check.
RelNote: "The `OnCreateDialogIncorrectCallback` lint check will no
longer crash when declaring a top level variable."
Test: kotlin anonymous object test
Bug: 189967522
Change-Id: I62de88c344cee0cb9deda26c9e5fc27247cf2d95
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/OnCreateDialogIncorrectCallbackDetector.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/OnCreateDialogIncorrectCallbackDetectorTest.kt
https://android-review.googlesource.com/1731936
Branch: androidx-main
commit 0a9efa914d322810f8dc8d9ba06e79d164c8892d
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Jun 09 13:01:36 2021
Fix lint crashes on kotlin top level properties
We need to handle cases where kotlin functions don't have a surrounding
class.
This change allows the surrounding class to be null and in that case we
just skip the check.
RelNote: "The `OnCreateDialogIncorrectCallback` lint check will no
longer crash when declaring a top level variable."
Test: kotlin anonymous object test
Bug: 189967522
Change-Id: I62de88c344cee0cb9deda26c9e5fc27247cf2d95
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/OnCreateDialogIncorrectCallbackDetector.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/OnCreateDialogIncorrectCallbackDetectorTest.kt
il...@google.com <il...@google.com> #12
We've improved this lint check and the updated check will be available in Fragment 1.4.0-alpha03.
co...@protonmail.com <co...@protonmail.com> #13
Looking forward to it. Thanks!
de...@gmail.com <de...@gmail.com> #14
Hello I am getting the same error probably after updating AGP version
```
../../src/main/java/com/sample/app/App.kt: Unexpected failure during lint analysis of App.kt (this is a bug in lint or one of the libraries it depends on)
Message: class androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector$UastHandler tried to access protected method 'org.jetbrains.kotlin.psi.KtClassOrObject org.jetbrains.uast.kotlin.KotlinUClass.getKtClass()' (androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector$UastHandler is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @10f53730; org.jetbrains.uast.kotlin.KotlinUClass is in unnamed module of loader java.net.URLClassLoader @4489af75)
The crash seems to involve the detector androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector.
You can try disabling it with something like this:
android {
lint {
disable "DialogFragmentCallbacksDetector"
}
}
Stack: IllegalAccessError:OnCreateDialogIncorrectCallbackDetector$UastHandler.visitClass(OnCreateDialogIncorrectCallbackDetector.kt:78)
←UElementVisitor$DispatchPsiVisitor.visitClass(UElementVisitor.kt:553)
←UElementVisitor$DelegatingPsiVisitor.visitClass(UElementVisitor.kt:1162)
←AbstractKotlinUClass.accept(AbstractKotlinUClass.kt:43)
←ImplementationUtilsKt.acceptList(implementationUtils.kt:29)
```
AGP 7.4.0-alpha03
Kotlin 1.6.20-M1
```
../../src/main/java/com/sample/app/App.kt: Unexpected failure during lint analysis of App.kt (this is a bug in lint or one of the libraries it depends on)
Message: class androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector$UastHandler tried to access protected method 'org.jetbrains.kotlin.psi.KtClassOrObject org.jetbrains.uast.kotlin.KotlinUClass.getKtClass()' (androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector$UastHandler is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @10f53730; org.jetbrains.uast.kotlin.KotlinUClass is in unnamed module of loader java.net.URLClassLoader @4489af75)
The crash seems to involve the detector androidx.fragment.lint.OnCreateDialogIncorrectCallbackDetector.
You can try disabling it with something like this:
android {
lint {
disable "DialogFragmentCallbacksDetector"
}
}
Stack: IllegalAccessError:OnCreateDialogIncorrectCallbackDetector$UastHandler.visitClass(OnCreateDialogIncorrectCallbackDetector.kt:78)
←UElementVisitor$DispatchPsiVisitor.visitClass(UElementVisitor.kt:553)
←UElementVisitor$DelegatingPsiVisitor.visitClass(UElementVisitor.kt:1162)
←AbstractKotlinUClass.accept(AbstractKotlinUClass.kt:43)
←ImplementationUtilsKt.acceptList(implementationUtils.kt:29)
```
AGP 7.4.0-alpha03
Kotlin 1.6.20-M1
de...@gmail.com <de...@gmail.com> #15
This is weird as the App.kt is a DaggerApplication and does not have any DialogFragment in it
de...@gmail.com <de...@gmail.com> #16
It got fix after updating androidx related dependency to 2.5.0-rc01
de...@gmail.com <de...@gmail.com> #17
Sorry I am still getting the same error in the CI CD pipelines but not in local machine, any idea?
co...@protonmail.com <co...@protonmail.com> #18
Are all of your deps up to date? This problem was fixed for me.
Description
Updated to compose beta08 and kotlin 1.5.10. Running lint gives me a few errors like this now:
Error: Unexpected failure during lint analysis of MyCustomClass.kt (this is a bug in lint or one of the libraries it depends on)