Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multiple exception handler invocation in Android (Kotlin#3056)
The AndroidExceptionPreHandler was changed in commit 5ea9339 to not invoke the uncaught exception pre-handler on Android Pie and above, and to instead invoke the thread's uncaught exception handler directly on those versions, as Android Pie had added logic in the default uncaught exception handler to ensure that the pre-handler would be invoked. However, the uncaught exception handler is already being invoked for all unhandled coroutine exceptions, so this change in the AndroidExceptionPreHandler caused the uncaught exception handler to be invoked twice in Android Pie and above. Since the default uncaught exception handler implementation in Android kills the app immediately, this normally wouldn't make a difference. However, if an app sets a custom uncaught exception handler (either at the thread or global level) that doesn't always kill the app, then the duplicate invocations might cause undesired or wrong behaviour. This is now fixed by removing the uncaught exception handler invocation from AndroidExceptionPreHandler. Since the pre-handler was introduced in Android Oreo, I have also added a minimum SDK check for Android Oreo as well. Also edited the documentation in the comments to add more details and context.
- Loading branch information