rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.22k stars 839 forks source link

[Bug]: App crashes when offline pack exists from a previous version of the library #2803

Closed ivari closed 1 year ago

ivari commented 1 year ago

Mapbox Implementation

Mapbox

Mapbox Version

10.13.0-beta.1

Platform

Android

@rnmapbox/maps version

main

Standalone component to reproduce

No component is needed. Issue reproduces without loading a map.

Observed behavior and steps to reproduce

Calling OfflineManager crashes the app.

Happens only when upgrading from an older version and an offline pack has been saved earlier.

Steps:

  1. install 10.0.0-beta.68 + 10.10.2
  2. create offline pack
  3. upgrade to #main + 10.13.0-beta.1
  4. call a method on OfflineManager, e.g. await MapboxGL.offlineManager.resetDatabase()
  5. app crashes

Expected behavior

App does not crash.

Notes / preliminary analysis

Each crash boils down to a single line failing to convert JSON.

Stacktrace:

04-18 00:49:30.212  6214  6214 D AndroidRuntime: Shutting down VM
04-18 00:49:30.215  6214  6214 E AndroidRuntime: FATAL EXCEPTION: main
04-18 00:49:30.215  6214  6214 E AndroidRuntime: Process: com.eagronommobile, PID: 6214
04-18 00:49:30.215  6214  6214 E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
04-18 00:49:30.215  6214  6214 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    ... 1 more
04-18 00:49:30.215  6214  6214 E AndroidRuntime: Caused by: org.json.JSONException: Value {"name":"default_offline_pack"} of type java.lang.String cannot be converted to JSONObject
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at org.json.JSON.typeMismatch(JSON.java:112)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at org.json.JSONObject.<init>(JSONObject.java:172)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at org.json.JSONObject.<init>(JSONObject.java:185)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.mapbox.rctmgl.utils.extensions.ValueKt.toJSONObject(Value.kt:8)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.mapbox.rctmgl.modules.RCTMGLOfflineModule.convertRegionsToJSON(RCTMGLOfflineModule.kt:374)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.mapbox.rctmgl.modules.RCTMGLOfflineModule.access$convertRegionsToJSON(RCTMGLOfflineModule.kt:93)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at com.mapbox.rctmgl.modules.RCTMGLOfflineModule$getPacks$1$run$1.run(RCTMGLOfflineModule.kt:251)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:942)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7872)
04-18 00:49:30.215  6214  6214 E AndroidRuntime:    ... 3 more
04-18 00:49:30.228   577   754 W ActivityTaskManager:   Force finishing activity com.eagronommobile/com.eagronom.mobile.MainActivity

Additional links and references

No response

ivari commented 1 year ago

FYI: Just edited first repro step, made a typo originally.

ivari commented 1 year ago

@mfazekas Thank you!

mfazekas commented 1 year ago

@ivari pls try with https://www.npmjs.com/package/@rnmapbox/maps/v/10.0.3-beta.0 and report if it fixes for you