Skip to content

Commit f8fa529

Browse files
committed
Remove old strictNullChecks backend
1 parent a4d991e commit f8fa529

File tree

3 files changed

+6
-43
lines changed

3 files changed

+6
-43
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class KotlinModule private constructor(
4747
strictNullChecks: Boolean = StrictNullChecks.enabledByDefault,
4848
val kotlinPropertyNameAsImplicitName: Boolean = KotlinPropertyNameAsImplicitName.enabledByDefault,
4949
val useJavaDurationConversion: Boolean = UseJavaDurationConversion.enabledByDefault,
50-
private val newStrictNullChecks: Boolean = NewStrictNullChecks.enabledByDefault,
50+
newStrictNullChecks: Boolean = NewStrictNullChecks.enabledByDefault,
5151
) : SimpleModule(KotlinModule::class.java.name, PackageVersion.VERSION) {
5252
/*
5353
* Prior to 2.18, an older Enum called SingletonSupport was used to manage feature.
@@ -67,8 +67,6 @@ class KotlinModule private constructor(
6767
)
6868
val enabledSingletonSupport: Boolean get() = singletonSupport
6969

70-
private val oldStrictNullChecks: Boolean = strictNullChecks
71-
7270
// To reduce the amount of destructive changes, no properties will be added to the public.
7371
val strictNullChecks: Boolean = if (strictNullChecks) {
7472
if (newStrictNullChecks) {
@@ -113,7 +111,7 @@ class KotlinModule private constructor(
113111

114112
val cache = ReflectionCache(reflectionCacheSize)
115113

116-
context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, oldStrictNullChecks))
114+
context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault))
117115

118116
if (singletonSupport) {
119117
context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier)
@@ -128,7 +126,7 @@ class KotlinModule private constructor(
128126
useJavaDurationConversion
129127
))
130128
context.appendAnnotationIntrospector(
131-
KotlinNamesAnnotationIntrospector(cache, newStrictNullChecks, kotlinPropertyNameAsImplicitName)
129+
KotlinNamesAnnotationIntrospector(cache, strictNullChecks, kotlinPropertyNameAsImplicitName)
132130
)
133131

134132
context.addDeserializers(KotlinDeserializers(cache, useJavaDurationConversion))

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ internal class KotlinValueInstantiator(
2222
private val cache: ReflectionCache,
2323
private val nullToEmptyCollection: Boolean,
2424
private val nullToEmptyMap: Boolean,
25-
private val nullIsSameAsDefault: Boolean,
26-
private val strictNullChecks: Boolean
25+
private val nullIsSameAsDefault: Boolean
2726
) : StdValueInstantiator(src) {
2827
private fun JavaType.requireEmptyValue() =
2928
(nullToEmptyCollection && this.isCollectionLikeType) || (nullToEmptyMap && this.isMapLikeType)
3029

3130
private fun KType.isGenericTypeVar() = javaType is TypeVariable<*>
3231

33-
private fun List<KTypeProjection>.markedNonNullAt(index: Int) = getOrNull(index)?.type?.isMarkedNullable == false
34-
3532
// If the argument is a value class that wraps nullable and non-null,
3633
// and the input is explicit null, the value class is instantiated with null as input.
3734
private fun requireValueClassSpecialNullValue(
@@ -104,35 +101,6 @@ internal class KotlinValueInstantiator(
104101
).wrapWithPath(this.valueClass, pname)
105102
}
106103
}
107-
} else if (strictNullChecks) {
108-
val arguments = paramType.arguments
109-
110-
// To make the behavior the same as deserialization of each element using NullsFailProvider,
111-
// first wrapWithPath with paramVal and key.
112-
val ex = when {
113-
propType.isCollectionLikeType && arguments.markedNonNullAt(0) -> {
114-
(paramVal as Collection<*>).indexOf(null).takeIf { it >= 0 }?.let {
115-
InvalidNullException.from(ctxt, jsonProp.fullName, jsonProp.type)
116-
.wrapWithPath(paramVal, it)
117-
}
118-
}
119-
propType.isMapLikeType && arguments.markedNonNullAt(1) -> {
120-
(paramVal as Map<*, *>).entries.find { (_, v) -> v == null }?.let { (k, _) ->
121-
InvalidNullException.from(ctxt, jsonProp.fullName, jsonProp.type)
122-
.wrapWithPath(paramVal, k.toString())
123-
}
124-
}
125-
propType.isArrayType && arguments.markedNonNullAt(0) -> {
126-
(paramVal as Array<*>).indexOf(null).takeIf { it >= 0 }?.let {
127-
InvalidNullException.from(ctxt, jsonProp.fullName, jsonProp.type)
128-
.wrapWithPath(paramVal, it)
129-
}
130-
}
131-
else -> null
132-
}
133-
134-
// Then, wrapWithPath with this property.
135-
ex?.let { throw it.wrapWithPath(this.valueClass, jsonProp.name) }
136104
}
137105

138106
bucket[paramDef] = paramVal
@@ -151,7 +119,6 @@ internal class KotlinInstantiators(
151119
private val nullToEmptyCollection: Boolean,
152120
private val nullToEmptyMap: Boolean,
153121
private val nullIsSameAsDefault: Boolean,
154-
private val strictNullChecks: Boolean
155122
) : ValueInstantiators {
156123
override fun findValueInstantiator(
157124
deserConfig: DeserializationConfig,
@@ -165,8 +132,7 @@ internal class KotlinInstantiators(
165132
cache,
166133
nullToEmptyCollection,
167134
nullToEmptyMap,
168-
nullIsSameAsDefault,
169-
strictNullChecks
135+
nullIsSameAsDefault
170136
)
171137
} else {
172138
// TODO: return defaultInstantiator and let default method parameters and nullability go unused? or die with exception:

src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinInstantiatorsTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class KotlinInstantiatorsTest {
1111
ReflectionCache(10),
1212
nullToEmptyCollection = false,
1313
nullToEmptyMap = false,
14-
nullIsSameAsDefault = false,
15-
strictNullChecks = false
14+
nullIsSameAsDefault = false
1615
)
1716

1817
@Test

0 commit comments

Comments
 (0)