Skip to content

Commit b96cdb9

Browse files
[android][v10] Add guard to prevent NRE on map.getStyle().styleLayers (rnmapbox#3595)
* 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 <mfazekas@szemafor.com> --------- Co-authored-by: Frederick Engelhardt <fre@vllc.dev> Co-authored-by: Miklós Fazekas <mfazekas@szemafor.com>
1 parent 465d341 commit b96cdb9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,15 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
11291129
Logger.e("MapView", "setSourceVisibility, map is null")
11301130
return
11311131
}
1132-
val style = mMap!!.getStyle();
1133-
style!!.styleLayers.forEach {
1132+
val style = mMap.getStyle();
1133+
1134+
val styleLayers = style?.styleLayers
1135+
if (styleLayers == null) {
1136+
Logger.e("MapView", "setSourceVisibility, map.getStyle().styleLayers is null")
1137+
return
1138+
}
1139+
1140+
styleLayers.forEach {
11341141
val layer = style.getLayer(it.id)
11351142
if ((layer != null) && match(layer, sourceId, sourceLayerId)) {
11361143
layer.visibility(

0 commit comments

Comments
 (0)