Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit f21d9872130100b23bd87c82f20bb94e1448bb63
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Oct 10 18:33:27 2023
Add a lint check for setting current state from coroutine
Since TestLifecycleOwner uses runBlocking it is not safe to set the currentState property, for instance, from the context of a coroutine, since it is thread-blocking. Instead, users should use the new setCurrentContext suspending function if using TestLifecycleOwner from something like runTest.
RelNote: "Providing a new Lint check to avoid setting the Lifecycle.State of the TestLifecycleOwner by using the currentState field when inside of a coroutine."
Test: TestLifecycleOwnerInCoroutineDetectorTest
Bug: 297880630
Change-Id: Icf728aa93a9aeca7c3cd89311289aae970d1f651
A lifecycle/lifecycle-runtime-testing-lint/build.gradle
A lifecycle/lifecycle-runtime-testing-lint/src/main/java/androidx/lifecycle/testing/lint/LifecycleRuntimeTestingIssueRegistry.kt
A lifecycle/lifecycle-runtime-testing-lint/src/main/java/androidx/lifecycle/testing/lint/TestLifecycleOwnerInCoroutineDetector.kt
A lifecycle/lifecycle-runtime-testing-lint/src/main/resources/META-INF/services/com.android.tools.lint.client.api.IssueRegistry
A lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/ApiLintVersionsTest.kt
A lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/TestLifecycleOwnerInCoroutineDetectorTest.kt
M lifecycle/lifecycle-runtime-testing/build.gradle
M settings.gradle
https://android-review.googlesource.com/2780871
Branch: androidx-main
commit f21d9872130100b23bd87c82f20bb94e1448bb63
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Oct 10 18:33:27 2023
Add a lint check for setting current state from coroutine
Since TestLifecycleOwner uses runBlocking it is not safe to set the currentState property, for instance, from the context of a coroutine, since it is thread-blocking. Instead, users should use the new setCurrentContext suspending function if using TestLifecycleOwner from something like runTest.
RelNote: "Providing a new Lint check to avoid setting the Lifecycle.State of the TestLifecycleOwner by using the currentState field when inside of a coroutine."
Test: TestLifecycleOwnerInCoroutineDetectorTest
Bug: 297880630
Change-Id: Icf728aa93a9aeca7c3cd89311289aae970d1f651
A lifecycle/lifecycle-runtime-testing-lint/build.gradle
A lifecycle/lifecycle-runtime-testing-lint/src/main/java/androidx/lifecycle/testing/lint/LifecycleRuntimeTestingIssueRegistry.kt
A lifecycle/lifecycle-runtime-testing-lint/src/main/java/androidx/lifecycle/testing/lint/TestLifecycleOwnerInCoroutineDetector.kt
A lifecycle/lifecycle-runtime-testing-lint/src/main/resources/META-INF/services/com.android.tools.lint.client.api.IssueRegistry
A lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/ApiLintVersionsTest.kt
A lifecycle/lifecycle-runtime-testing-lint/src/test/java/androidx/lifecycle/runtime/testing/lint/TestLifecycleOwnerInCoroutineDetectorTest.kt
M lifecycle/lifecycle-runtime-testing/build.gradle
M settings.gradle
il...@google.com <il...@google.com> #3
This has been added internally and will be available in Lifecycle 2.7.0-alpha03.
pr...@google.com <pr...@google.com> #4
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.lifecycle:lifecycle-runtime-testing:2.7.0-alpha03
Description
We want to add a lint check to guide users to using the new `TestLifecycleOwner` API `setCurrentState` from the context of a coroutine (i.e. `runTest`), rather than accessing the `currentState` property directly.