-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: avoid crash by converting lateinit to nullable #17482
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
fix: avoid crash by converting lateinit to nullable #17482
Conversation
BrayanDSO
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.
The code doesn't look pretty, but not crashing is better than crashing
|
Yeah, I wasn't sure how to handle it without doing a lot of either |
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.
With the changes in this PR when I go in the card browser and select different decks all I see in the toolbar is the title All Decks(it never changes) and the number of cards of the deck that I actually selected in the dialog.
The whole code around deck selection really needs to be refactored, it's just a mess in its current form.
agreed |
53a71a5 to
539cf5c
Compare
criticalAY
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.
LGTM!
lukstbit
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.
Everything seems to be in order now!
Purpose / Description
Avoid a crash seen in ACRA by the evil use of
lateinitwhich is just the sleeper NullPointerException of modern Kotlin timesFixes
https://ankidroid.org/acra/app/1/bug/260934/report/c4097fac-9c67-460b-986c-017cc1a98313
Approach
There is apparently an init pathway where the flows for CardBrowser start up a DeckSpinner and that can try to select where it should be, before
onCollectionLoadedis finished, so the spinner doesn't have all the data it expects because it hasn't actually been initialized fully.Instead of just blindly expecting itself to be initialized now, the deck list in the spinner is nullable, and if it is null, then the spinner just defaults to all decks / position -1
I assume when it is initialized that the spinner will set itself up correctly later, but most importantly it won't crash now
The diff shouldn't look so bad if ignore space is turned on, because mostly I'm encapsulating the init blocks in
let {}to handle the new nullability cleanlyHow Has This Been Tested?
open the app with this patch installed, go to card browser and check the spinner is still working, it's still working
Learning (optional, can help others)
Anyone accepting PRs that have lateinit, or
!!etc are asking for trouble 🧐Checklist
Please, go through these checks before submitting the PR.