Skip to content

Commit db75ee2

Browse files
Duy PhạmDuy Phạm
authored andcommitted
Fix ConcurrentModificationException in addMarker method
1 parent aaba24b commit db75ee2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib-compose/src/main/java/com/what3words/components/compose/maps/extensions/MapStateExtensions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.what3words.components.compose.maps.extensions
33
import com.what3words.components.compose.maps.models.W3WMarker
44
import com.what3words.core.types.common.W3WError
55
import com.what3words.core.types.common.W3WResult
6+
import java.util.Collections
67

78
internal fun MutableMap<String, MutableList<W3WMarker>>.addMarker(
89
listName: String,
910
marker: W3WMarker,
1011
): W3WResult<W3WMarker> {
1112
// Get or create the current list of markers (using MutableList for in-place updates)
12-
val currentList = this.getOrPut(listName) { mutableListOf() }
13+
val currentList = this.getOrPut(listName) { Collections.synchronizedList(mutableListOf()) }
1314

1415
// Check if a marker with the same ID already exists
1516
val index = currentList.indexOfFirst { it.square.id == marker.square.id }

0 commit comments

Comments
 (0)