Skip to content

Commit c79968c

Browse files
committed
Added code clarification
1 parent a1fe327 commit c79968c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

bson-kotlin/src/main/kotlin/org/bson/codecs/kotlin/DataClassCodec.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ internal data class DataClassCodec<T : Any>(
105105
// Optional parameters (with defaults) are left absent so callBy uses the default value.
106106
fieldNamePropertyModelMap.values.forEach {
107107
if (it.param !in args && !it.param.isOptional) {
108+
// Only error for concrete types (KClass). Generic type parameters (KTypeParameter)
109+
// may be nullable at runtime even though isMarkedNullable is false at the
110+
// declaration site (e.g. Box<T>(val boxed: T) instantiated as Box<String?>).
108111
if (!it.param.type.isMarkedNullable && it.param.type.classifier is KClass<*>) {
109112
throw CodecConfigurationException(
110113
"Required field '${it.fieldName}' is missing from the document for ${kClass.simpleName} data class")

0 commit comments

Comments
 (0)