From dc19ef445b3d9b645b74cbea418c83eba62dde60 Mon Sep 17 00:00:00 2001 From: Farkhod Sayfitdinov Date: Wed, 15 Apr 2026 15:58:31 +0500 Subject: [PATCH] fix: null-guard teardownChannels to avoid NPE on engine detach 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 --- .../com/unact/yandexmapkit/full/InitFull.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/android/src/main/java/com/unact/yandexmapkit/full/InitFull.java b/android/src/main/java/com/unact/yandexmapkit/full/InitFull.java index 8b4017e2..c23912f2 100644 --- a/android/src/main/java/com/unact/yandexmapkit/full/InitFull.java +++ b/android/src/main/java/com/unact/yandexmapkit/full/InitFull.java @@ -57,21 +57,30 @@ public void setupChannels(BinaryMessenger messenger, Context context) { pedestrianMethodChannel.setMethodCallHandler(yandexPedestrian); } - @SuppressWarnings({"ConstantConditions"}) public void teardownChannels() { - searchMethodChannel.setMethodCallHandler(null); - searchMethodChannel = null; - - suggestMethodChannel.setMethodCallHandler(null); - suggestMethodChannel = null; - - drivingMethodChannel.setMethodCallHandler(null); - drivingMethodChannel = null; - - bicycleMethodChannel.setMethodCallHandler(null); - bicycleMethodChannel = null; - - pedestrianMethodChannel.setMethodCallHandler(null); - pedestrianMethodChannel = null; + if (searchMethodChannel != null) { + searchMethodChannel.setMethodCallHandler(null); + searchMethodChannel = null; + } + + if (suggestMethodChannel != null) { + suggestMethodChannel.setMethodCallHandler(null); + suggestMethodChannel = null; + } + + if (drivingMethodChannel != null) { + drivingMethodChannel.setMethodCallHandler(null); + drivingMethodChannel = null; + } + + if (bicycleMethodChannel != null) { + bicycleMethodChannel.setMethodCallHandler(null); + bicycleMethodChannel = null; + } + + if (pedestrianMethodChannel != null) { + pedestrianMethodChannel.setMethodCallHandler(null); + pedestrianMethodChannel = null; + } } }