From b96cdb9c151d2a0dd984e4afecdbf9fb3b57c02e Mon Sep 17 00:00:00 2001 From: Frederick Engelhardt <31741411+FrederickEngelhardt@users.noreply.github.com> Date: Tue, 27 Aug 2024 04:48:21 -0700 Subject: [PATCH] [android][v10] Add guard to prevent NRE on map.getStyle().styleLayers (#3595) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add guard to prevent NRE crashing android apps on launch of map without styleLayers being a valid array * Update android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt Use early return instead of optional chaining an iterator. Co-authored-by: Miklós Fazekas --------- Co-authored-by: Frederick Engelhardt Co-authored-by: Miklós Fazekas --- .../rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt index 95398fb6c..688f3a637 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt @@ -1129,8 +1129,15 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie Logger.e("MapView", "setSourceVisibility, map is null") return } - val style = mMap!!.getStyle(); - style!!.styleLayers.forEach { + val style = mMap.getStyle(); + + val styleLayers = style?.styleLayers + if (styleLayers == null) { + Logger.e("MapView", "setSourceVisibility, map.getStyle().styleLayers is null") + return + } + + styleLayers.forEach { val layer = style.getLayer(it.id) if ((layer != null) && match(layer, sourceId, sourceLayerId)) { layer.visibility(