michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.28k stars 220 forks source link

Fatal Exception: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer #225

Closed jplandry908 closed 1 year ago

jplandry908 commented 1 year ago

Hi @michalchudziak. I just deployed v3.0.4 to production yesterday and now seeing this crash in Crashlytics.

Fatal Exception: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at com.reactnativecommunity.geolocation.BaseLocationManager.putIntoMap(BaseLocationManager.java:87) at com.reactnativecommunity.geolocation.BaseLocationManager.locationToMap(BaseLocationManager.java:114) at com.reactnativecommunity.geolocation.AndroidLocationManager.getCurrentLocationData(AndroidLocationManager.java:65) at com.reactnativecommunity.geolocation.GeolocationModule.lambda$getCurrentPosition$5(GeolocationModule.java:2) at com.reactnativecommunity.geolocation.GeolocationModule.$r8$lambda$t41cae4n5bC7nBTx28QaLYkphmM(GeolocationModule.java) at com.reactnativecommunity.geolocation.GeolocationModule$$InternalSyntheticLambda$0$91f4ef2eb723dca66eebec8e9f3016f60b21edcb2fc2b20caf573c25881a0fc3$0.invoke(GeolocationModule.java:8) at com.reactnativecommunity.geolocation.GeolocationModule.lambda$requestAuthorization$3(GeolocationModule.java:22) at com.reactnativecommunity.geolocation.GeolocationModule.$r8$lambda$bQHDBTEa3_YJk8TGsNzRzMJWzEM(GeolocationModule.java) at com.reactnativecommunity.geolocation.GeolocationModule$$InternalSyntheticLambda$0$355dae8561e89dcdc924d00a9eaa1af3dc01b559bdb7ce0a50946a9b43dbe235$3.invoke(GeolocationModule.java:11) at com.facebook.react.bridge.PromiseImpl.resolve(PromiseImpl.java:10) at com.facebook.react.modules.permissions.PermissionsModule.checkPermission(PermissionsModule.java:21) at com.reactnativecommunity.geolocation.GeolocationModule.requestAuthorization(GeolocationModule.java:64) at com.reactnativecommunity.geolocation.GeolocationModule.getCurrentPosition(GeolocationModule.java:21) at com.reactnativecommunity.geolocation.RNCGeolocationModule.getCurrentPosition(RNCGeolocationModule.java:2) at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:148) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:147) at com.facebook.jni.NativeRunnable.run(NativeRunnable.java) at android.os.Handler.handleCallback(Handler.java:900) at android.os.Handler.dispatchMessage(Handler.java:103) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java) at android.os.Looper.loop(Looper.java:219) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:37) at java.lang.Thread.run(Thread.java:929)

jplandry908 commented 1 year ago

Hi @michalchudziak. I don't know java very well, but I think the code below will fix this issue.

BaseLocationManager.java

OLD:

if (value instanceof Integer || value instanceof Long) {
     map.putInt(key, (Integer) value);
} ...

NEW:

if (value instanceof Integer) {
     map.putInt(key, (Integer) value);
} else if (value instanceof Long) {
     map.putInt(key, ((Long) value).intValue());
} ...
michalchudziak commented 1 year ago

Hey, thank you for reporting! Would you mind doing a PR with the proposed changes? I'll be glad to include them :)

jplandry908 commented 1 year ago

Done! https://github.com/michalchudziak/react-native-geolocation/pull/227

michalchudziak commented 1 year ago

Fixed with https://github.com/michalchudziak/react-native-geolocation/pull/227 - to be included in 3.0.5

jplandry908 commented 1 year ago

Hi @michalchudziak. Just curious when you are planning on releasing 3.0.5 with this fix? I have been running the app in production with this patch without any more issues.

michalchudziak commented 1 year ago

Hey! 3.0.5 is live :)

jplandry908 commented 1 year ago

Thanks @michalchudziak!