Skip to content

fix: null-guard teardownChannels to avoid NPE on engine detach#414

Open
fsayfitdinov wants to merge 1 commit intoUnact:masterfrom
fsayfitdinov:fix-teardown-npe
Open

fix: null-guard teardownChannels to avoid NPE on engine detach#414
fsayfitdinov wants to merge 1 commit intoUnact:masterfrom
fsayfitdinov:fix-teardown-npe

Conversation

@fsayfitdinov
Copy link
Copy Markdown

Summary

InitFull.teardownChannels() dereferences five @Nullable MethodChannel fields without null checks. The @SuppressWarnings({\"ConstantConditions\"}) annotation hides the static analysis warning, but the runtime risk is real: if FlutterActivity is destroyed before onAttachedToEngine completes (or onDetachedFromEngine fires a second time), the fields are null and the first call (searchMethodChannel.setMethodCallHandler(null)) throws NullPointerException.

Firebase Crashlytics stack trace observed on Android 14 production device:

```
Caused by java.lang.NullPointerException
at com.unact.yandexmapkit.full.InitFull.teardownChannels (InitFull.java:62)
at com.unact.yandexmapkit.full.InitFull.onDetachedFromEngine (InitFull.java:35)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy
at io.flutter.embedding.engine.FlutterEngine.destroy
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach
at io.flutter.embedding.android.FlutterActivity.onDestroy
at android.app.Activity.performDestroy
```

This patch adds null guards around each channel teardown and removes the now-unnecessary @SuppressWarnings annotation. Behavior is unchanged for the normal lifecycle path.

Test plan

  • Package builds cleanly (`flutter pub get` + `flutter analyze` in a consumer app)
  • Manual: rapid activity destroy mid-map-init no longer crashes
  • Crashlytics: confirm the NPE stops appearing after a release with this fix

🤖 Generated with Claude Code

InitFull.teardownChannels dereferenced @nullable MethodChannel fields
without null checks. When FlutterActivity is destroyed before
onAttachedToEngine completes (or is detached twice), the fields are null
and setMethodCallHandler() throws NullPointerException.

Fixes the Crashlytics report:
  Caused by java.lang.NullPointerException
    at InitFull.teardownChannels (InitFull.java:62)
    at InitFull.onDetachedFromEngine (InitFull.java:35)
    at FlutterEngineConnectionRegistry.destroy
    at Activity.performDestroy
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