Skip to content
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

Fix Dispatchers.Main not being fully initialized on Android and Swing #3101

Merged
merged 4 commits into from Dec 21, 2021

Conversation

dkhalanskyjb
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb commented Dec 20, 2021

  • If unitTests.returnDefaultValues=true is set on Android, then
    Looper.getMainLooper() may return null. The type system of
    Kotlin is tricked to believe that the method can't ever return
    null, so doesn't check for it anywhere. As a result, despite not
    being fully initialized, Dispatchers.Main is considered
    non-missing.
  • When running in a headless environment, Swing crashes, but
    the dispatcher successfully initializes nonetheless.

This was not an issue before, as it only surfaced when
Dispatchers.Main was used. However, now Main is the source of
time for delays, so any delay will throw something
incomprehensible if this happens.

If `unitTests.returnDefaultValues=true` is set, then
`Looper.getMainLooper()` may return `null`. The type system of
Kotlin is tricked to believe that the method can't ever return
`null`, so doesn't check for it anywhere. As a result, despite not
being fully initialized, `Dispatchers.Main` is considered
correct.

This was not an issue before, as it only surfaced when
`Dispatchers.Main` was used. However, now, `Main` is the source of
time for delays, so any delay will throw something
incomprehensible if this happens.
This is relevant for headless environments.
@dkhalanskyjb dkhalanskyjb changed the title Fix Dispatchers.Main not being fully initialized on Android Fix Dispatchers.Main not being fully initialized on Android and Swing Dec 21, 2021
@qwwdfsad qwwdfsad merged commit bbb175b into develop Dec 21, 2021
@qwwdfsad qwwdfsad deleted the fix-uninitialized-android-Main branch December 21, 2021 14:47
yorickhenning pushed a commit to yorickhenning/kotlinx.coroutines that referenced this pull request Jan 28, 2022
…Kotlin#3101)

* Fix Dispatchers.Main not being fully initialized on Android

If `unitTests.returnDefaultValues=true` is set, then
`Looper.getMainLooper()` may return `null`. The type system of
Kotlin is tricked to believe that the method can't ever return
`null`, so doesn't check for it anywhere. As a result, despite not
being fully initialized, `Dispatchers.Main` is considered
correct.

This was not an issue before, as it only surfaced when
`Dispatchers.Main` was used. However, now, `Main` is the source of
time for delays, so any delay will throw something
incomprehensible if this happens.
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this pull request Sep 14, 2022
…Kotlin#3101)

* Fix Dispatchers.Main not being fully initialized on Android

If `unitTests.returnDefaultValues=true` is set, then
`Looper.getMainLooper()` may return `null`. The type system of
Kotlin is tricked to believe that the method can't ever return
`null`, so doesn't check for it anywhere. As a result, despite not
being fully initialized, `Dispatchers.Main` is considered
correct.

This was not an issue before, as it only surfaced when
`Dispatchers.Main` was used. However, now, `Main` is the source of
time for delays, so any delay will throw something
incomprehensible if this happens.
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.

None yet

2 participants