fix: null-guard teardownChannels to avoid NPE on engine detach#414
Open
fsayfitdinov wants to merge 1 commit intoUnact:masterfrom
Open
fix: null-guard teardownChannels to avoid NPE on engine detach#414fsayfitdinov wants to merge 1 commit intoUnact:masterfrom
fsayfitdinov wants to merge 1 commit intoUnact:masterfrom
Conversation
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
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.
Summary
InitFull.teardownChannels()dereferences five@Nullable MethodChannelfields without null checks. The@SuppressWarnings({\"ConstantConditions\"})annotation hides the static analysis warning, but the runtime risk is real: ifFlutterActivityis destroyed beforeonAttachedToEnginecompletes (oronDetachedFromEnginefires a second time), the fields are null and the first call (searchMethodChannel.setMethodCallHandler(null)) throwsNullPointerException.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
@SuppressWarningsannotation. Behavior is unchanged for the normal lifecycle path.Test plan
🤖 Generated with Claude Code