Use type converter that cannot return null for date to avoid crash #1573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is adding a type converter that never returns null to address a crash we've seen a sudden increase in on Sentry.
The root of the crash seems to be that a null
Long
is being retrieved from thepodcast_episodes
database table. This should never happen because that column is not allowed to be null. This is the generated code that is leading to the error:This PR adds a
SafeDate
typealias for theDate
class along with aTypeConverter
that will never return null and therefore handles providing validDate
objects even if it is passed a null. I'm doing this instead of updating the currentDateTypeConverter
because we need the type converter to be able to return null dates #1390 (comment). This is what the generated code looks like with the new type converter:Fixes #1572
Testing Instructions
I have not found a way to directly reproduce this error in an unaltered app, so let's do two tests, one with the unaltered app, and one with an altered build that forces the app to handle a null value from the database.
1. Unaltered app
2. Force the type converter to handle a null value
ShouldNotBeNullDateTypeConverter::toDate
method so that it always returnsDate(Instant.EPOCH.toEpochMilli())
(i.e., what it would return ifnull
was passed to the method).Checklist
./gradlew spotlessApply
to automatically apply formatting/linting)modules/services/localization/src/main/res/values/strings.xml