Skip to content

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer #365

@sahil-sukhwani

Description

@sahil-sukhwani

Summary

BaseLocationManager.putIntoMap crashes on Android 12+ with a ClassCastException:
java.lang.Long cannot be cast to java.lang.Integer.

Environment

  • Library version: 3.3.0 (also reproduces on 3.4.0)
  • React Native version: 0.73.9
  • Android version/device: Android 12, Xiaomi 11 Lite 5G NE (real device)

Steps to reproduce

  1. Call Geolocation.getCurrentPosition (or start observing location).
  2. When Google Play services populates Location.getExtras() with Long values
    (e.g. GNSS satellite count), the library tries to cast to Integer.

Stack trace

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
    at com.reactnativecommunity.geolocation.BaseLocationManager.putIntoMap(BaseLocationManager.java:53)
    at com.reactnativecommunity.geolocation.BaseLocationManager.locationToMap(BaseLocationManager.java:38)
    ...

Expected behaviour

Extras should be forwarded without crashing (Long should be handled safely).

Proposed fix

Treat any Number generically or handle Long before Integer.
I can send a PR with the change if that helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions