-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Compile Warnings As Errors] WordPress Module - Resolve Coroutines Warnings #17210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1st Warning Messages: "This declaration is experimental and its usage should be marked with '@kotlinx.coroutines.ExperimentalCoroutinesApi' or '@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)'" Adding the '@OptIn(ExperimentalCoroutinesApi::class)' annotation on these functions is the recommended action to resolve this 'GlobalScope' warnings. However, this results to the below '@OptIn' warnings: 2nd Warning Message: "This annotation should be used with the compiler argument '-Xopt-in=kotlin.RequiresOptIn'" Adding the '-Xopt-in=kotlin.RequiresOptIn' free compiler argument is the recommended action to resolve this '@OptIn' warning.
Warning Messages: "'UI/DEFAULT_SCOPE: String' is deprecated. Implement CoroutineScope interface and cancel all child coroutines in onCleared/onDestroy/.."ª It seems that both, the deprecated named 'UI_SCOPE' and 'DEFAULT_SCOPE' coroutine scopes, that are being provided by the [ThreadModule] module, are no longer being utilized within this codebase and thus, they can be now safely removed. There was no need for any migration either.
Warning Messages: "@synchronized annotation is not applicable to suspend functions and lambdas" This coroutines warning is suppressed, that is, instead of it being resolved, since it seems that: 1. Adding the '@synchronized' annotation was done deliberately, and 2. Changing that is a bit complicated as it would need a bit more thought to properly fix this, using [Mutex] or otherwise. For more info see: - Fix crash in UploadStarter on Samsung devices with Android 5 #10878 (Introduced In): https://github.com/wordpress-mobile/WordPress-Android/ pull/10878 - Forbid @synchronized annotation on suspend functions (Kotlin Issue): https://youtrack.jetbrains.com/issue/KT-27333/ Forbid-Synchronized-annotation-on-suspend-functions - Coroutines and Java Synchronization Don't Mix (Blog Post: https://blog.danlew.net/2020/01/28/ coroutines-and-java-synchronization-dont-mix/
Warning Messages: "This declaration is experimental and its usage should be marked with '@kotlinx.coroutines.ExperimentalCoroutinesApi' or '@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)'"
Warning Messages: "'poll(): E?' is deprecated. Deprecated in the favour of 'tryReceive'. Please note that the provided replacement does not rethrow channel's close cause as 'poll' did, for the precise replacement please refer to the 'poll' documentation"
This is done so that the '@ExperimentalCoroutinesApi' annotation is only presented itself once per test suite and avoid having to think and add this boilerplate configuration multiple times, per test configuration or function, whenever and if it is needed.
|
|||||||||||
| 💡 Scan this QR code with your Android phone to download and install the APK directly on it. | ||
| App | WordPress | |
| Build Flavor | Jalapeno | |
| Build Type | Debug | |
| Commit | 43949f1 | |
|
|||||||||||
| 💡 Scan this QR code with your Android phone to download and install the APK directly on it. | ||
| App | Jetpack | |
| Build Flavor | Jalapeno | |
| Build Type | Debug | |
| Commit | 43949f1 | |
|
👋 @AjeshRPai ! FYI: After talking to Jirka about this comment I left for him here, I decided to go ahead and resolve this As such, I added an additional label to this PR, the Then, and when I'll have my finally solution to this problem ready (probably tomorrow), I'll push it here and inform you about the change so you can take a final look at it (plus test it). 🧑🏭 |
Warning Messages: "@synchronized annotation is not applicable to suspend functions and lambdas" It turns out that this '@synchronized' solution were already replacing the previous (d5b9948) 'Mutex' solution, and this, due to the fact that the existing (back then) 'Mutex' solution were causing crashes on Samsung devices running Android 5 (API Level 21). However, this repo, and thus both, the WordPress and Jetpack apps, are no longer supporting these devices as the current 'minSdkVersion' is '24' (Android 7). Thus, this '@synchronized' annotation can be now safely removed and the 'Mutex' solution reverting back. For more info see: - Fix crash in UploadStarter on Samsung devices with Android 5 #10877 (Introduced In): https://github.com/wordpress-mobile/WordPress-Android/ pull/10877/ - ExceptionInInitializerError #10827 (Crash Report): #10827 - NoSuchFieldException with AtomicReferenceFieldUpdater on Samsung Android 5.0.x devices #490 (Coroutines Issue): Kotlin/kotlinx.coroutines#490
|
FYI: This is now done, I have resolved the PS: You will find more info about the reasoning behind this change, along with a couple associated links, within the commit message itself. |
AjeshRPai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing me with all the details for the review in commit messages as well as in the description. As always, it’s a pleasure to review your PR since I will get the context of the change/links of the references in your PR description and commit messages themselves. 🙌
I have
- tested the PR by going through the changes in every commit and reading the reference links mentioned in the commit messages and everything LGTM 👍🏼
- done a smoke testing of the WordPress and jetpack app and everything looks fine 👍🏼
- tested the synchronized to mutex changes. Published a post on offline mode with the following steps. It works as expected 🟢 👍🏼
1. Turn off the internet connection
2. Create a post
3. Publish it
4. Turn on internet connection + pull to refresh
5. Make sure the post gets uploaded
Am going to approve but not merge the PR so that anyone from @wordpress-mobile/apps-infrastructure or @Jirka can have a look. Please feel free to merge the PR at your convenience. Nice work 🙌🏼
|
Thank you so much for reviewing and testing this @AjeshRPai , you are awesome! 🙇
This sounds like a good plan! 🙏 PS: As always, I am humbled by your kind words, thank you! 😊 |
|
👋 @malinajirka !
Any last thoughts on it before I go merging this to |
|
I haven't tested it but the changes LGTM! ⭐ |
|
Coolio, thank you for the confirmation @malinajirka , that's all I needed! 🙇 |


Parent: #17173
Partially Closes: #17181
This PR resolves all
Coroutinesrelated warnings for theWordPressmodule:This declaration is experimental and its usage should be marked with '@kotlinx.coroutines.ExperimentalCoroutinesApi' or '@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)''XYZ' is deprecated. Implement CoroutineScope interface and cancel all child coroutines in xyz@Synchronized annotation is not applicable to suspend functions and lambdas+ Question [❓]: see comment @malinajirkaThis declaration is experimental and its usage should be marked with '@kotlinx.coroutines.ExperimentalCoroutinesApi' or '@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)''Xyz' is deprecated. Deprecated in the favour of 'xyz'. Please note that the provided replacement does not rethrow channel's close cause as 'poll' did, for the precise replacement please refer to the 'poll' documentationWarnings Resolution List:
Warnings Suppression List:
Refactor List:
Documentation List:
PS: @AjeshRPai I added you as the main reviewer, that is, in addition to @wordpress-mobile/apps-infrastructure team itself, but randomly, since I want someone from the
WordPress Androidteam to primarily sign-off on that change. 🥇FYI: I am going to randomly add more of you in those PRs that will follow, just so you become more aware of this change and how close we are on enabling
allWarningsAsErrorsby default everywhere. 🎉To test:
WordPressandJetpackapps, and see if they are both working as expected.PS: Also note the additional testing instructions as specified in this comment here.
Regression Notes
N/A
See
To testsection above.N/A
PR submission checklist:
RELEASE-NOTES.txtif necessary.