Skip to content

Fix NPE in KeyboardVisibilityListener when userInfo is nil#2694

Open
onseok wants to merge 1 commit intoJetBrains:jb-mainfrom
onseok:fix-keyboard-listener-npe
Open

Fix NPE in KeyboardVisibilityListener when userInfo is nil#2694
onseok wants to merge 1 commit intoJetBrains:jb-mainfrom
onseok:fix-keyboard-listener-npe

Conversation

@onseok
Copy link

@onseok onseok commented Jan 18, 2026

Description

Fix NullPointerException in KeyboardVisibilityListener when a keyboard notification is posted without userInfo.

Problem

When native iOS code manually posts a keyboard notification without userInfo (e.g., NotificationCenter.default.post(name: UIKeyboardWillHideNotification, object: nil)), the animationOptions property crashes due to an unsafe cast.

The current implementation:

return value?.unsignedIntegerValue() as UIViewAnimationOptions

When userInfo is nil, value becomes null, and casting null to UIViewAnimationOptions throws a NullPointerException.

Crash stack trace

image
kfun:androidx.compose.ui.window.NativeKeyboardVisibilityListener.<get-animationOptions>#internal
kfun:androidx.compose.ui.window.NativeKeyboardVisibilityListener.$imp:keyboardWillHide:#internal

Solution

Add null-safe handling with a default value, consistent with the duration and endFrame properties in the same file.

Fixes https://youtrack.jetbrains.com/issue/CMP-9548

Testing

  1. Integrate a Compose Multiplatform library that uses ComposeUIViewController in an iOS app
  2. From native iOS code, post a keyboard hide notification without userInfo:
NotificationCenter.default.post(
    name: UIResponder.keyboardWillHideNotification,
    object: nil
    // userInfo is nil
)
  1. Before fix: App crashes with NullPointerException
  2. After fix: No crash, gracefully handles nil userInfo

Release Notes

Fixes - iOS

  • Fixed crash in KeyboardVisibilityListener when keyboard notification has nil userInfo

Google CLA

Sign the Google Contributor's License Agreement at https://cla.developers.google.com to let us upstream your code to Google's AOSP repository

@google-cla
Copy link

google-cla bot commented Jan 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@onseok onseok force-pushed the fix-keyboard-listener-npe branch from f83ed2b to a9d225f Compare January 18, 2026 01:40
When a keyboard notification is posted without userInfo (e.g., manually from native iOS code), the animationOptions property crashes due to unsafe cast. This change adds null-safe handling consistent with duration and endFrame properties in the same file.

Fixes https://youtrack.jetbrains.com/issue/CMP-9548
@onseok onseok force-pushed the fix-keyboard-listener-npe branch from a9d225f to 6aa8c5d Compare January 18, 2026 01:53
@MatkovIvan MatkovIvan requested a review from ASalavei February 25, 2026 19:06
@ASalavei
Copy link

ASalavei commented Mar 2, 2026

There is a conflict in the code review. As far as I see the bug already was fixed.

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