Pushwoosh / pushwoosh-flutter

Pushwoosh Flutter Plugin
Other
8 stars 16 forks source link

[Bug]: NullPointerException in PushwooshPlugin.onDetachedFromEngine #94

Open bravoure7 opened 3 days ago

bravoure7 commented 3 days ago

Documentation

Description

We're experiencing a NullPointerException in PushwooshPlugin.onDetachedFromEngine when using the Pushwoosh Flutter plugin, specifically with a 1.83% crash occurrence rate in production (monitored via AppMetrica). The crash appears to be triggered during detachment, although it’s unclear if it’s related to lifecycle events or specific platform behaviors.

Bug severity

Low

Steps to Reproduce

  1. Initialize the plugin following the documented initialization process.
  2. Use onPushReceived, onPushAccepted, and onDeepLinkOpened listeners.
  3. During app usage, the crash intermittently occurs when detaching the engine. I was unable to reproduce the crash on my devices.

Your Pushwoosh Flutter plugin version

2.2.31

flutter package version

3.24.3

Last worked Pushwoosh Flutter plugin version (if any)

No response

Affected platforms

Affected OS versions and/or devices

The crash occurs on various Android devices across a wide range of OS versions, from Android 8 to Android 14, affecting multiple device models.

Workaround

The crash occurs in the Pushwoosh plugin, specifically in the file located at Source/pushwoosh/android/src/main/java/com/pushwoosh/plugin/PushwooshPlugin.java within the onDetachedFromEngine method at line 97. The actual crash happens on line 98, where PushwooshPlugin.channel attempts to call setMethodCallHandler, but channel itself is null. I suspect this issue arises because onDetachedFromEngine may be called twice by mistake, leading to PushwooshPlugin.channel being set to null on line 106 within the method. {DF9134DF-4C8F-48B6-8D01-76F3C2139CA7}

Relevant log output

java.lang.RuntimeException: Unable to destroy activity {ru.ideast.championat/ru.ideast.championat.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.k.setMethodCallHandler(io.flutter.plugin.common.k$c)' on a null object reference
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6080)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:6113)
    at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47)
    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.k.setMethodCallHandler(io.flutter.plugin.common.k$c)' on a null object reference
    at com.pushwoosh.plugin.PushwooshPlugin.onDetachedFromEngine(Unknown Source)
    at io.flutter.embedding.engine.b.remove(Unknown Source)
    at io.flutter.embedding.engine.b.remove(Unknown Source)
    at io.flutter.embedding.engine.b.removeAll(Unknown Source)
    at io.flutter.embedding.engine.b.destroy(Unknown Source)
    at io.flutter.embedding.engine.FlutterEngine.destroy(Unknown Source)
    at io.flutter.embedding.android.e.t(Unknown Source)
    at io.flutter.embedding.android.d.onDestroy(Unknown Source)
    at android.app.Activity.performDestroy(Activity.java:8864)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1419)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:6067)
    ... 13 more
enginseer-dev commented 2 days ago

Hi @bravoure7! Thank you for your report! Please let us discuss it within the team and get back to you.