Skip to content

Commit 6b5a2d3

Browse files
authored
fix: prevent NPE in LatLngBounds.contains by adding null checks for positions (#1675)
1 parent bce193a commit 6b5a2d3

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void run() {
524524
}
525525

526526
for (final MarkerWithPosition marker : markersToRemove) {
527-
boolean onScreen = visibleBounds.contains(marker.position);
527+
boolean onScreen = marker.position != null && visibleBounds.contains(marker.position);
528528
if (onScreen && mAnimate) {
529529
final Point point = mSphericalMercatorProjection.toPoint(marker.position);
530530
final Point closest = findClosestCluster(newClustersOnScreen, point);

library/src/main/java/com/google/maps/android/clustering/view/DefaultAdvancedMarkersClusterRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public void run() {
453453
if (DefaultAdvancedMarkersClusterRenderer.this.mClusters != null && mAnimate) {
454454
existingClustersOnScreen = new ArrayList<>();
455455
for (Cluster<T> c : DefaultAdvancedMarkersClusterRenderer.this.mClusters) {
456-
if (shouldRenderAsCluster(c) && visibleBounds.contains(c.getPosition())) {
456+
if (shouldRenderAsCluster(c) && c.getPosition() != null && visibleBounds.contains(c.getPosition())) {
457457
Point point = mSphericalMercatorProjection.toPoint(c.getPosition());
458458
existingClustersOnScreen.add(point);
459459
}
@@ -492,7 +492,7 @@ public void run() {
492492
if (mAnimate) {
493493
newClustersOnScreen = new ArrayList<>();
494494
for (Cluster<T> c : clusters) {
495-
if (shouldRenderAsCluster(c) && visibleBounds.contains(c.getPosition())) {
495+
if (shouldRenderAsCluster(c) && c.getPosition() != null && visibleBounds.contains(c.getPosition())) {
496496
Point p = mSphericalMercatorProjection.toPoint(c.getPosition());
497497
newClustersOnScreen.add(p);
498498
}

library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public void run() {
492492

493493
// Remove the old markers, animating them into clusters if zooming out.
494494
for (final MarkerWithPosition marker : markersToRemove) {
495-
boolean onScreen = visibleBounds.contains(marker.position);
495+
boolean onScreen = marker.position != null && visibleBounds.contains(marker.position);
496496
// Don't animate when zooming out more than 3 zoom levels.
497497
// TODO: drop animation based on speed of device & number of markers to animate.
498498
if (!zoomingIn && zoomDelta > -3 && onScreen && mAnimate) {

0 commit comments

Comments
 (0)