Element accessors on a map should return null on non-existing keys, but instead
myMapOfThings["item3"] throws java.util.NoSuchElementException: Key item3 is missing in the map.
When a Map is initialized (via SnapshotStateMap) in ViewModel with
var myMapOfThings: MutableMap<String, MyType> by mutableStateMapOf(
"item1" to MyType(),
"item2" to MyType()
)
All documentation seems to indicate it should behave as a true map
* Create a instance of [MutableMap]<K, V> that is observable and can be snapshot.
* @see mutableMapOf
and as declared for Map in package kotlin.collections
/**
* Returns the value corresponding to the given [key], or `null` if such a key is not present in the map.
*/
public operator fun get(key: K): V?
Is this a bug or am I missing something?
(Build Info for Reference)
kotlin_version = '1.8.0'
kotlin_plugin_version = '1.7.0'
compose_version = '1.2.0'
coroutines_version = '1.6.1'
compileSdk 32
buildToolsVersion = "30.0.3"
minSdk 28
targetSdk 32
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}