Skip to content

Reader PhotoViewer no longer crashes with null imgUrl#10834

Merged
malinajirka merged 3 commits intodevelopfrom
issue/10831-reader-img-non-null
Nov 28, 2019
Merged

Reader PhotoViewer no longer crashes with null imgUrl#10834
malinajirka merged 3 commits intodevelopfrom
issue/10831-reader-img-non-null

Conversation

@jd-alexander
Copy link
Copy Markdown
Contributor

Fixes #10831

To test:

  1. Simulate the imgUrl as being null.
  2. Go to Reader.
  3. Click on an article.
  4. Click on an image.
  5. The app shouldn't crash.

For further discussion, it just shows a loading spinner.

PR submission checklist:

  • I have considered adding unit tests where possible.

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link
Copy Markdown

peril-wordpress-mobile bot commented Nov 22, 2019

You can test the changes on this Pull Request by downloading the APK here.

@malinajirka
Copy link
Copy Markdown
Contributor

Thanks @jd-alexander!

The solution works as expected. However, I like to follow the Fail-Fast principle. Changing the non-null type to nullable prevents the app from crashing, but we'll never know if the users can see their images (and that we have bugs in the app). In an ideal world, everything would be written in Kotlin and we wouldn't have this problem. We are not there yet, but I think it'd be nice to try to keep the interfaces as clean as possible. Wdyt?

ReaderPhotoView.loadImage() is invoked from two places

  1. setImageUrl(..) -> which invokes mHiResImageUrl = ReaderUtils.getResizedImageUrl( which always returns non-null string -> this scenario is safe.
  2. onLayout(..) -> this is apparently the scenario in which the mHiResImageUrl is null (stack trace in Sentry confirms it).

How would you feel about modifying ReaderPhotoViewerFragment so it's never opened with a null imgUrl -> we could show a toast message and log an exception into Sentry in case someone tries to open it with a null imgUrl. This solution would prevent the app from crashing. Moreover it'd help us investigate how come we are opening the fragment with a null url.
Another solution which is simpler and is ok imo is to check we don't call loadImage from onLayout unless the url is set. We'd still just hide the bug we have, but we wouldn't change the interface of ImageManager which is used all over the app and could potential hide multiple bugs. Wdyt?

@jd-alexander
Copy link
Copy Markdown
Contributor Author

jd-alexander commented Nov 25, 2019

Thanks @jd-alexander!

The solution works as expected. However, I like to follow the Fail-Fast principle. Changing the non-null type to nullable prevents the app from crashing, but we'll never know if the users can see their images (and that we have bugs in the app). In an ideal world, everything would be written in Kotlin and we wouldn't have this problem. We are not there yet, but I think it'd be nice to try to keep the interfaces as clean as possible. Wdyt?

Thanks for the review! Let's see what can be done.

ReaderPhotoView.loadImage() is invoked from two places

setImageUrl(..) -> which invokes mHiResImageUrl = ReaderUtils.getResizedImageUrl( which always returns non-null string -> this scenario is safe.
onLayout(..) -> this is apparently the scenario in which the mHiResImageUrl is null (stack trace in Sentry confirms it).

How would you feel about modifying ReaderPhotoViewerFragment so it's never opened with a null imgUrl -> we could show a toast message and log an exception into Sentry in case someone tries to open it with a null imgUrl. This solution would prevent the app from crashing. Moreover it'd help us investigate how come we are opening the fragment with a null url.

Another solution which is simpler and is ok imo is to check we don't call loadImage from onLayout unless the url is set. We'd still just hide the bug we have, but we wouldn't change the interface of ImageManager which is used all over the app and could potential hide multiple bugs. Wdyt?

Yes, I just did some investigation and I think this might be the appropriate solution. We could be having an issue where the onLayout is being called before setImage which is causing the null issue. Wdyt?

Copy link
Copy Markdown
Contributor

@malinajirka malinajirka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! ;)

@malinajirka malinajirka merged commit 16b94a4 into develop Nov 28, 2019
@malinajirka malinajirka deleted the issue/10831-reader-img-non-null branch November 28, 2019 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNo...

2 participants