Skip to content

fix: prevent NPE crash on Android 15/16 by guarding null DecorView - #31

Open
Barson0588 wants to merge 1 commit into
JSvandijk:mainfrom
Barson0588:fix/android15-insets-npe
Open

fix: prevent NPE crash on Android 15/16 by guarding null DecorView#31
Barson0588 wants to merge 1 commit into
JSvandijk:mainfrom
Barson0588:fix/android15-insets-npe

Conversation

@Barson0588

Copy link
Copy Markdown

Problem

The app crashes immediately on launch on Android 15/16 devices (reproduced on a Honor GT Pro running MagicOS 10 / Android 16):

java.lang.RuntimeException: Unable to start activity
  ComponentInfo{com.t3code.app/com.t3code.app.MainActivity}:
  java.lang.NullPointerException: Attempt to invoke virtual method
  'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()'
  on a null object reference
    at com.t3code.app.MainActivity.onCreate(MainActivity.java:102)

Root cause

In onCreate, getWindow().getInsetsController() is called before setContentView(). Internally Window.getInsetsController() dereferences getDecorView(). On Android 15/16 (SDK 35/36) edge-to-edge is enforced and the window's DecorView is not yet installed at this point, so getDecorView() returns null and the dereference throws a NullPointerException.

The existing if (insetsController != null) guard does not help, because the NPE happens inside getInsetsController(), not on its return value.

Fix

Fetch the DecorView first and bail out if it is null before 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

  • Reproduced the crash via adb logcat + dumpsys dropbox.
  • Applied a bytecode-equivalent smali patch to the built T3Code-v1.1.0.apk, re-signed it, and confirmed the app launches normally (process stays alive, no NPE in logcat).
  • This source change mirrors that verified patch exactly.

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.
@Barson0588
Barson0588 requested a review from JSvandijk as a code owner August 17, 2026 06:54
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.

1 participant