fix: prevent NPE crash on Android 15/16 by guarding null DecorView - #31
Open
Barson0588 wants to merge 1 commit into
Open
fix: prevent NPE crash on Android 15/16 by guarding null DecorView#31Barson0588 wants to merge 1 commit into
Barson0588 wants to merge 1 commit into
Conversation
getWindow().getInsetsController() internally calls getDecorView(), which can return null on Android 15/16 (enforced edge-to-edge) when invoked before setContentView(). Guard against a null DecorView so the app no longer crashes on launch.
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.
Problem
The app crashes immediately on launch on Android 15/16 devices (reproduced on a Honor GT Pro running MagicOS 10 / Android 16):
Root cause
In
onCreate,getWindow().getInsetsController()is called beforesetContentView(). InternallyWindow.getInsetsController()dereferencesgetDecorView(). On Android 15/16 (SDK 35/36) edge-to-edge is enforced and the window'sDecorViewis not yet installed at this point, sogetDecorView()returnsnulland the dereference throws aNullPointerException.The existing
if (insetsController != null)guard does not help, because the NPE happens insidegetInsetsController(), not on its return value.Fix
Fetch the
DecorViewfirst and bail out if it isnullbefore reading the insets controller. On Android 15/16 these insets/color calls are deprecated no-ops anyway, so skipping them is harmless; on Android 11–14 (API 30–34) the original behavior is preserved.Verification
adb logcat+dumpsys dropbox.T3Code-v1.1.0.apk, re-signed it, and confirmed the app launches normally (process stays alive, no NPE in logcat).