fix(android): null-check getRootWindowInsets() in onEnd to prevent NPE when view is detached#55
Open
Franjanko wants to merge 1 commit intoionic-team:mainfrom
Conversation
…E when view is detached
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a null-check on ViewCompat.getRootWindowInsets() in the onEnd method of WindowInsetsAnimationCompat.Callback to prevent a NullPointerException crash when the view is already detached from the window.
Change Type
Fix
Rationale / Problems Fixed
ViewCompat.getRootWindowInsets(rootView) can return null when the root view is detached from the window (e.g. during activity tear-down or rapid navigation). The original code called .isVisible() directly on the result without any null-check, causing a fatal crash:
Fatal Exception: java.lang.NullPointerException
at com.capacitorjs.plugins.keyboard.Keyboard$1.onEnd(Keyboard.java:109)
Additionally, getRootWindowInsets() was being called twice unnecessarily — once for isVisible() and once for getInsets(). The fix consolidates both calls into a single assignment with an early-return guard.
Tests or Reproductions
The crash is reliably triggered by detaching the view while a keyboard animation is in progress (e.g. navigating away from a screen that has an open soft keyboard). After the fix, the onEnd callback returns early instead of crashing.
Screenshots / Media
N/A
Platforms Affected
Android
Notes / Comments
This affects @capacitor/keyboard 8.0.1, which is the latest available version at time of writing. The fix is minimal and non-breaking: if insets is null, the keyboard event is simply not dispatched for that animation cycle.