Skip to content

Marker: no hit test without a bitmap - #1814

Merged
devemux86 merged 1 commit into
mapsforge:masterfrom
cpesch:fix/marker-contains-null-bitmap
Aug 23, 2026
Merged

devemux86 merged 1 commit into
mapsforge:masterfrom
cpesch:fix/marker-contains-null-bitmap

Conversation

@cpesch

@cpesch cpesch commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Marker#contains() dereferences this.bitmap, while Marker#draw() returns early for a null or destroyed one. The constructor documents the bitmap as nullable ("the initial Bitmap of this marker (may be null)"), so a marker whose icon failed to load throws on the first hit test:

java.lang.NullPointerException: Cannot invoke "org.mapsforge.core.graphics.Bitmap.getWidth()" because "this.bitmap" is null
	at org.mapsforge.map.layer.overlay.Marker.contains(Marker.java:58)
	at ...onTap(...)
	at ...mousePressed(...)

Seen in RouteConverter (mapsforge 0.29.0, awt): one failed renderSvg() of the marker icon at startup turned every subsequent mouse press near a selected position into an uncaught NPE on the AWT event thread. Application-side hardening is in cpesch/RouteConverter#323; this is the upstream half.

Since a marker without a usable bitmap draws nothing, it cannot be hit either, so contains() now returns false for that case - the same condition draw() already uses.

🤖 Generated with Claude Code

Marker#contains dereferences the bitmap, unlike Marker#draw, which returns early for a
null or destroyed one. A Marker created with a null bitmap - the constructor documents it
as allowed - therefore throws a NullPointerException as soon as it is hit tested:

    java.lang.NullPointerException: Cannot invoke "org.mapsforge.core.graphics.Bitmap.getWidth()" because "this.bitmap" is null
        at org.mapsforge.map.layer.overlay.Marker.contains(Marker.java:58)

Since such a marker draws nothing, it cannot be hit either.

Co-Authored-By: Claude Opus 5 <[email protected]>
@devemux86 devemux86 added the bug label Aug 23, 2026
@devemux86 devemux86 added this to the 0.31.0 milestone Aug 23, 2026
@devemux86
devemux86 merged commit 184f08d into mapsforge:master Aug 23, 2026
1 check passed
@devemux86

Copy link
Copy Markdown
Collaborator

@cpesch Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants