cgeo: ArrayIndexOutOfBoundsException in Mapsforge
A user reported non-reproducible crashes in a scenario where he repeatedly changed from map to a cache, added waypoint with his current position and returned to the map.
His logfile only contains this crash, not sure if it is related (as the time stamp provided by the user does not match the log time stamp (wrong day)).
03-03 07:44:39.257 10687 10687 E AndroidRuntime: FATAL EXCEPTION: main
03-03 07:44:39.257 10687 10687 E AndroidRuntime: Process: cgeo.geocaching, PID: 10687
03-03 07:44:39.257 10687 10687 E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: length=1874; index=1875
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:385)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:398)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at org.mapsforge.map.layer.Layers.get(Layers.java:336)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at org.mapsforge.map.android.input.TouchGestureHandler.onSingleTapConfirmed(TouchGestureHandler.java:263)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:300)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6798)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
03-03 07:44:39.257 10687 10687 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
--- System information ---
Device: ONEPLUS A3003 (OnePlus3, OnePlus)
Android version: 8.0.0
Android build: ONEPLUS A3003_28_180704
c:geo version: 2021.02.14
Google Play services: enabled - 21.06.13 (040400-358943053)
Low power mode: inactive
Compass capabilities: yes
Rotation vector sensor: present
Orientation sensor: present
Magnetometer & Accelerometer sensor: present
Direction sensor used: rotation vector
Hide caches: own/found disabled archived
Hide waypoints: original visited
HW acceleration: enabled (default state)
System language: da_DK / user-defined language:
System date format: dd/MM/y
Debug mode active: no
System internal c:geo dir: /data/user/0/cgeo.geocaching (21,9 GB free) internal
User storage c:geo dir: /storage/emulated/0/cgeo (21,8 GB free) external non-removable
Geocache data: /storage/emulated/0/Android/data/cgeo.geocaching/files/GeocacheData (21,8 GB free) external non-removable
Database: /data/user/0/cgeo.geocaching/databases/data (99,2 MB) on system internal storage
Last backup: 16. jan. 07.19
GPX import path: /storage/emulated/0/cgeo/gpx
GPX export path: /storage/emulated/0/cgeo/gpx
Offline maps path: /storage/emulated/0/cgeo/maps
Map render theme path:
Live map mode: true
Global filter: display all caches
Sailfish OS detected: false
Fine location permission: granted
Write external storage permission: granted
Geocaching sites enabled:
geocaching.com: Logged in (Login OK) / PREMIUM
Geocaching.com date format: dd/MM/yyyy
Installed c:geo plugins: contacts
BRouter connection available: false
--- End of system information ---
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 35 (35 by maintainers)
Commits related to this issue
- rel to #10128: use mapsforge version modified by eddiemuc which might solve arrayindexoutofbounds problem — committed to eddiemuc/cgeo by eddiemuc 3 years ago
- rel to #10128: use mapsforge version modified by eddiemuc which might solve arrayindexoutofbounds problem — committed to cgeo/cgeo by eddiemuc 3 years ago
- rel to #10128: use mapsforge version 0.16 with fix from eddiemuc for arrayindexoutofboundsexception — committed to eddiemuc/cgeo by eddiemuc 3 years ago
- rel to #10128: use mapsforge version 0.16 with fix from eddiemuc for arrayindexoutofboundsexception (#11978) — committed to cgeo/cgeo by eddiemuc 3 years ago
- rel to #10128: switch used mapsforge fork to cgeo repo — committed to eddiemuc/cgeo by eddiemuc 3 years ago
- rel to #10128: switch used mapsforge fork to cgeo repo (#12025) — committed to cgeo/cgeo by eddiemuc 3 years ago
At least part of the weekend is done now, time for some statistics.
Here is the statistic for the ArrayIndexOutOfBoundsException in Mapsforge in October 2021 (by app version):
The fix candidate is active in our beta as of 24.10. This maps to apk 20211023.apk. The other beta versions (and productive versions) don’t contain the fix. Here are all beta version relevant for October 2021:

The picture shows us:
In summary, I thing this shows that the fix is working. I will reach out to mapsforge with this data.
@eddiemuc That was the reason I revived and updated that repository, so your PR fits perfectly and we can use that reference until we used the official release to (better) prove to the mapsforge team, that your change solves our issue.
Lets leave this issue open as a reminder to refer again to the mapsforge repo once the change is merged and/or released there.
@eddiemuc I will do it tomorrow.