transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.54k stars 424 forks source link

com.facebook.react.bridge.NoSuchKeyException #1965

Closed rabbiss closed 2 months ago

rabbiss commented 2 months ago

Your Environment

Expected Behavior

No crashes or exceptions.

Actual Behavior

App crash on com.facebook.react.bridge.NoSuchKeyException

Steps to Reproduce

Reported by Android vitals, so unfortunately no debug logs available. I have not been able to reproduce this issue while debugging either.

Context

I have this stacktrace from Android vitals:

Exception com.facebook.react.bridge.NoSuchKeyException: latitude
  at com.facebook.react.bridge.ReadableNativeMap.getValue (ReadableNativeMap.java:113)
  at com.facebook.react.bridge.ReadableNativeMap.getValue (ReadableNativeMap.java:117)
  at com.facebook.react.bridge.ReadableNativeMap.getDouble (ReadableNativeMap.java:154)
  at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.buildGeofence (RNBackgroundGeolocationModule.java:702)
  at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.addGeofences (RNBackgroundGeolocationModule.java:682)
  at java.lang.reflect.Method.invoke
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188)
  at com.facebook.jni.NativeRunnable.run
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
  at android.os.Looper.loopOnce (Looper.java:240)
  at android.os.Looper.loop (Looper.java:351)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
  at java.lang.Thread.run (Thread.java:1012)

We have multiple reports, right now hundreds of devices affected. Just wondering if you can point me in the right direction, as I don't know where to start looking for the problem.

No such key exception points to latitude. I have checked our geofence methods on the Javascript side, and "latitude" is always defined (it's a fixed value, so no chance of being undefined):

await BackgroundGeolocation.addGeofence({
    identifier: "mock_identifier",
    radius: 200,
    latitude: 60.123123123,
    longitude: 24.123123123,
    notifyOnEntry: true,
    notifyOnExit: false,
    notifyOnDwell: false,
})

I know this isn't much, but any help would be appreciated!

christocracy commented 2 months ago

at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.buildGeofence (RNBackgroundGeolocationModule.java:702)

Line 702

if (config.hasKey("latitude"))         { builder.setLatitude(config.getDouble("latitude")); }

Crashes here within react-native's ReadableMap.getValue.

Can you reproduce this?

christocracy commented 2 months ago

I added your code into my SampleApp. The geofence is successfully created and monitored.

The SampleApp uses "react-native": "0.73.0",

await BackgroundGeolocation.addGeofence({
    identifier: "mock_identifier",
    radius: 200,
    latitude: 60.123123123,
    longitude: 24.123123123,
    notifyOnEntry: true,
    notifyOnExit: false,
    notifyOnDwell: false,
})
03-12 11:08:09.830  9179  9179 D TSLocationManager: ╔═════════════════════════════════════════════
03-12 11:08:09.830  9179  9179 D TSLocationManager: ║ TSGeofenceManager monitoring 1/1
03-12 11:08:09.830  9179  9179 D TSLocationManager: ╠═════════════════════════════════════════════
03-12 11:08:09.830  9179  9179 D TSLocationManager: ╟─ 🎾  mock_identifier
03-12 11:08:09.830  9179  9179 D TSLocationManager: ╚═════════════════════════════════════════════

I see it in the wilderness of Suomi (small green circle).

IMG_0621

christocracy commented 2 months ago

Check your code: you MUST be setting latitude: null somewhere. I can reproduce with the following:

await BackgroundGeolocation.addGeofence({
        identifier: "mock_identifier",
        radius: 200,
        latitude: null, // <---------------------- null
        longitude: 24.123123123,
        notifyOnEntry: true,
        notifyOnExit: false,
        notifyOnDwell: false,
})
03-12 11:21:42.253 11566 11609 E AndroidRuntime: com.facebook.react.bridge.NoSuchKeyException: latitude
03-12 11:21:42.253 11566 11609 E AndroidRuntime:    at com.facebook.react.bridge.ReadableNativeMap.getValue(ReadableNativeMap.java:113)
03-12 11:21:42.253 11566 11609 E AndroidRuntime:    at com.facebook.react.bridge.ReadableNativeMap.getValue(ReadableNativeMap.java:117)
03-12 11:21:42.253 11566 11609 E AndroidRuntime:    at com.facebook.react.bridge.ReadableNativeMap.getDouble(ReadableNativeMap.java:154)
03-12 11:21:42.253 11566 11609 E AndroidRuntime:    at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.buildGeofence(RNBackgroundGeolocationModule.java:702)
rabbiss commented 2 months ago

Yes, I can now reproduce the error with debugger connected. It is a safe bet that this null value is a bug in the code. Thanks for investigating!