react-native-ble-plx icon indicating copy to clipboard operation
react-native-ble-plx copied to clipboard

Null pointer exception when we unsubscribe the monitor and clear the ble instance

Open arpitgarg23 opened this issue 4 years ago • 1 comments

Prerequisites

Issue with 2.0.2 as bleAdapter might be null while with 2.0.1 it was never null. Crash

Expected Behavior

It should have null check for bleAdpater and should handle null pointer exceptipn.

Steps to Reproduce

Terminate and close the ble connection with device. Please provide detailed steps for reproducing the issue.

Context

2021-05-26 20:37:19.192 27037-27173/com.xx.xx E/unknown:ReactNative: Exception in native call
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.polidea.multiplatformbleadapter.BleAdapter.cancelTransaction(java.lang.String)' on a null object reference
        at com.polidea.reactnativeble.BleClientManager.cancelTransaction(BleClientManager.java:107)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:164)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:764)
  • Library version: X.Y.Z
  • Platform: Android/
  • Platform logs (logcat/XCode):
  • JS logs:
  • Contents of the package.json file:
  • Formatted code sample or link to a repository:
![BLE_ErrorWelchAllyn](https://user-images.githubusercontent.com/41066669/119688024-45fb3f00-be65-11eb-917d-e0352f767965.png)

@ReactMethod
    public void destroyClient() {
        bleAdapter.destroyClient();
        bleAdapter = null;
    }

    // Mark: Common --------------------------------------------------------------------------------

    @ReactMethod
    public void cancelTransaction(String transactionId) {
        bleAdapter.cancelTransaction(transactionId);
    }

arpitgarg23 avatar May 26 '21 15:05 arpitgarg23

We are experiencing this bug as well. Could you confirm this issue is not present in 2.0.1?

Jurpp avatar May 25 '22 09:05 Jurpp

bug still present in 2.0.3

scinfu avatar Apr 06 '23 09:04 scinfu

If I understand you correctly, you destroyed the adapter and then called a function on it. You won't be able to call functions from it because it no longer exists.