-
Notifications
You must be signed in to change notification settings - Fork 137
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
Avoid null pointer exception when creating new stores #10534
Avoid null pointer exception when creating new stores #10534
Conversation
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Generated by 🚫 Danger |
AnalyticsTracker.KEY_URL to storeData.domain!!, | ||
AnalyticsTracker.KEY_URL to storeData.domain, |
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 domain value is only for tracking purposes. So in the case of process death, it will be null and the !!
will be causing the app to crash. Removed it. For the very few corner cases where storeData is null, we'll be tracking a null
value, but is not a problem.
@@ -83,6 +83,10 @@ class StoreInstallationViewModel @Inject constructor( | |||
init { | |||
if (!savedStateHandle.contains(STORE_DATA_KEY)) { | |||
storeData = newStore.data | |||
if (storeData.siteId == null) { | |||
storeData = storeData.copy(siteId = appPrefsWrapper.createdStoreSiteId) |
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.
In case the values from memory were whipped due to process death, we retrieve the required siteId
for the new site from sharedPreferences.
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 working on this @JorgeMucientes!
I've tested the app before the changes and after the changes and I can confirm it fixes the crash. However, it seems the solution ignores all the previous user choices. I tried selecting an industry and I killed the app. It seemed the store data were completely empty and my selection wasn't being taken into account. Wdyt?
Hey @malinajirka. Thanks for the review! However, I agree that we should probably save everything into DB and ensure all the data survives process death. But that would require several changes and I think is out of scope for this crash fix, so I've created a new issue to tackle that as a different task. Wdyt? |
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.
because they are the only options that have an impact on the new store and thus are essential. The rest of the data is kept in memory because is "a nice to have" since its is merely used for tracking purposes.
Ohh, interesting - I thought the choices are taken into consideration for customized content of the newly created site => that's how it works (or used to work at least) in the WordPress/Jetpack apps.
If that's truly the case and it doesn't have any impact on the UX, I agree this solution is good enough for this edge case. If it'd be affecting the final output, I'd personally prefer exiting the site creation flow and forcing users into starting over. Storing everything into the DB is definitely the best possible solution, but the required effort might not be worth it.
I'm approving the PR, feel free to merge it. Thanks!
Just a couple clarifications @malinajirka
In the future afaik is meant to have an impact. For now, they are just options we sent to Tracks and to Woo backend for a better understanding of Woo Express customers.
Unfortunately, that is not an option or would be very complicated as it would require deleting the new site before the user start customising it. The moment the user clicks on "Try for free" in store creation first step, a new site is created immediately. So even if you abandon the process right away, the site is already created and will be present in the site picker the next time they open the app or the web. |
Fixes crash: #10525
Description
Avoid null pointer exceptions during store creation when the Android system process death happens for the app.
Crash in action:
crash.mp4
Testing instructions
adb shell am kill com.woocommerce.android.dev
while the app is in backgroundFixed
fixCrash.mp4
RELEASE-NOTES.txt
if necessary.