-
Notifications
You must be signed in to change notification settings - Fork 130
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
Attempt to fix a crash that could occur when formatting dates and times #13393
Conversation
SimpleDateFormat is not thread safe, and reusing for multiple calls where there is a change of multi threading can lead to crashes, see https://stackoverflow.com/a/18383395
0774b03
to
6167832
Compare
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #13393 +/- ##
=========================================
Coverage 41.10% 41.10%
Complexity 6486 6486
=========================================
Files 1325 1325
Lines 77572 77572
Branches 10694 10694
=========================================
Hits 31889 31889
Misses 42850 42850
Partials 2833 2833 ☔ View full report in Codecov by Sentry. |
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.
Great find, @hichamboushaba! LGTM! 👍🏻
Closes: #13390
Description
This PR is an attempt to fix the linked crash, the above crash happens when we try to format dates, and looking online lead me to this StackOverflow answer https://stackoverflow.com/a/18383395, which matches our case, as we are using the same
SimpleFormatDate
instances for the whole lifetime ofDateUtils
class, and multi-threading is involved (for example with the paging library inOrderListItemDataSource
).I tried to reproduce the crash manually by making multiple concurrent calls, but I failed, but I think this fix by using computed properties should fix the crash, as we'll use each instance just once.
Steps to reproduce
Just a quick check of the top-level screens should be enough.
Testing information
Tested and confirmed no regression.
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: