I have a `data class` that has a parameter `metada...
# announcements
b
I have a
data class
that has a parameter
metadata: List<Item>
, and I'm creating it from a nullable with:
metadata?.map { Item(it.key, it.value) } ?: listOf()
. Which is compiling fine, but when metadata is null I'm getting:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
a
@bj0 is it possible that metadata contains nullable items? The Elvis operator catches null lists, but
Item(it.key, it.value)
will throw, when either
key
or
value
is null (Depending on the definition of
Item
)
a
that syntax works fine for me in a small test, can you make a reproduceable test case? (being able to get such an intrinsics exception does smell)
If the input to the transform is coming from XML, is your XML deserialisation library putting nulls into a property you've declared in Kotlin as non-nullable? or is the input to the transform a Java data class with platform nullability on the key/value properties?
b
it was from
SimpleXML
and I print to adb
metadata
, which is itself null, when it happens. I think it might be a compiler bug though because sometimes when I build and run it, it does not happen (i'm using the same test xml over and over)