Skip to content

[Bug] Null safe bug fix #21

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

Merged
merged 3 commits into from
May 28, 2020
Merged

[Bug] Null safe bug fix #21

merged 3 commits into from
May 28, 2020

Conversation

Leo-Neat
Copy link

No description provided.

@Leo-Neat Leo-Neat requested a review from nic0lette May 28, 2020 16:23
val display = windowManager.defaultDisplay
display.getMetrics(displayMetrics)
val display = windowManager?.defaultDisplay
display?.getMetrics(displayMetrics)
Copy link
Member

@nic0lette nic0lette May 28, 2020

Choose a reason for hiding this comment

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

If these are null, then it probably returns a height of 0, which seems like it would cause problems elsewhere which may be much more difficult to track down.
Would it make sense to explicitly throw in these situations? That is, something like:

val windowManager = context.getSystemService(WindowManager::class.java)
        ?: throw IllegalStateException("Could not get WindowManager")

(I realized after that there's a Kotlin extension method that works on all versions of Android for this, so it's not necessary to directly use ContextCompat)

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thanks for the help

@Leo-Neat Leo-Neat merged commit 8a91f1d into googlesamples:master May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants