Skip to content

Commit 1ddf63f

Browse files
committed
Recaftor
Cut out strictNullCheck
1 parent c7606d2 commit 1ddf63f

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/deser/value_instantiator/KotlinValueInstantiator.kt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ internal class KotlinValueInstantiator(
2828
// @see com.fasterxml.jackson.module.kotlin._ported.test.StrictNullChecksTest#testListOfGenericWithNullValue
2929
private fun ValueParameter.isNullishTypeAt(index: Int) = arguments.getOrNull(index)?.isNullable ?: true
3030

31+
private fun strictNullCheck(
32+
ctxt: DeserializationContext,
33+
jsonProp: SettableBeanProperty,
34+
paramDef: ValueParameter,
35+
paramVal: Any
36+
) {
37+
// If an error occurs, Argument.name is always non-null
38+
// @see com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.Argument
39+
when {
40+
paramVal is Collection<*> && !paramDef.isNullishTypeAt(0) && paramVal.any { it == null } ->
41+
"collection" to paramDef.arguments[0].name!!
42+
paramVal is Array<*> && !paramDef.isNullishTypeAt(0) && paramVal.any { it == null } ->
43+
"array" to paramDef.arguments[0].name!!
44+
paramVal is Map<*, *> && !paramDef.isNullishTypeAt(1) && paramVal.values.any { it == null } ->
45+
"map" to paramDef.arguments[1].name!!
46+
else -> null
47+
}?.let { (paramType, itemType) ->
48+
throw MissingKotlinParameterException(
49+
parameter = paramDef,
50+
processor = ctxt.parser,
51+
msg = "Instantiation of $itemType $paramType failed for JSON property ${jsonProp.name} due to null value in a $paramType that does not allow null values"
52+
).wrapWithPath(this.valueClass, jsonProp.name)
53+
}
54+
}
55+
3156
override fun createFromObjectWith(
3257
ctxt: DeserializationContext,
3358
props: Array<out SettableBeanProperty>,
@@ -75,25 +100,7 @@ internal class KotlinValueInstantiator(
75100
).wrapWithPath(this.valueClass, jsonProp.name)
76101
}
77102

78-
if (strictNullChecks && paramVal != null) {
79-
// If an error occurs, Argument.name is always non-null
80-
// @see com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.Argument
81-
when {
82-
paramVal is Collection<*> && !paramDef.isNullishTypeAt(0) && paramVal.any { it == null } ->
83-
"collection" to paramDef.arguments[0].name!!
84-
paramVal is Array<*> && !paramDef.isNullishTypeAt(0) && paramVal.any { it == null } ->
85-
"array" to paramDef.arguments[0].name!!
86-
paramVal is Map<*, *> && !paramDef.isNullishTypeAt(1) && paramVal.values.any { it == null } ->
87-
"map" to paramDef.arguments[1].name!!
88-
else -> null
89-
}?.let { (paramType, itemType) ->
90-
throw MissingKotlinParameterException(
91-
parameter = paramDef,
92-
processor = ctxt.parser,
93-
msg = "Instantiation of $itemType $paramType failed for JSON property ${jsonProp.name} due to null value in a $paramType that does not allow null values"
94-
).wrapWithPath(this.valueClass, jsonProp.name)
95-
}
96-
}
103+
if (strictNullChecks && paramVal != null) strictNullCheck(ctxt, jsonProp, paramDef, paramVal)
97104

98105
bucket[idx] = paramVal
99106
}

0 commit comments

Comments
 (0)