Skip to content

Commit 44c331c

Browse files
authored
Merge pull request #1042 from k163377/remove-old-strict-null-checks
Remove old StrictNullChecks
2 parents a4d991e + e927ca4 commit 44c331c

File tree

12 files changed

+29
-230
lines changed

12 files changed

+29
-230
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@
254254
<!-- removed -->
255255
<exclude>com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException</exclude>
256256
<!-- internal -->
257+
<exclude>
258+
com.fasterxml.jackson.module.kotlin.KotlinInstantiators#KotlinInstantiators(com.fasterxml.jackson.module.kotlin.ReflectionCache,boolean,boolean,boolean,boolean)
259+
</exclude>
260+
<exclude>
261+
com.fasterxml.jackson.module.kotlin.KotlinValueInstantiator#KotlinValueInstantiator(com.fasterxml.jackson.databind.deser.std.StdValueInstantiator,com.fasterxml.jackson.module.kotlin.ReflectionCache,boolean,boolean,boolean,boolean)
262+
</exclude>
257263
</excludes>
258264
</parameter>
259265
</configuration>

release-notes/CREDITS-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Contributors:
1818
# 2.21.0 (not yet released)
1919

2020
WrongWrong (@k163377)
21+
* #1042: Remove old StrictNullChecks
2122
* #1041: Remove MissingKotlinParameterException
2223
* #1039: Update settings for 2.20
2324

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Co-maintainers:
1818

1919
2.21.0 (not yet released)
2020

21+
#1042: The old StrictNullChecks backend has been removed.
22+
This improves the throughput of deserialization slightly.
2123
#1041: The deprecated MissingKotlinParameterException has been removed.
2224
#1039: Kotlin has been upgraded to 2.1.x.
2325

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ enum class KotlinFeature(internal val enabledByDefault: Boolean) {
4040
*
4141
* With this disabled, the default, collections which are typed to disallow null members (e.g. `List<String>`)
4242
* may contain null values after deserialization.
43-
* Enabling it protects against this but has significant performance impact.
43+
* Enabling this will cause an [InvalidNullException] to be thrown if null is entered.
44+
*
45+
* Internally, it will be the same as if [JsonSetter] (contentNulls = FAIL) had been granted.
46+
*
47+
* Benchmarks show that it can check for illegal nulls with throughput nearly identical to the default (see [jackson-module-kotlin#719]).
4448
*/
45-
@Deprecated(
46-
level = DeprecationLevel.ERROR,
47-
message = "This option will be migrated to the new backend in 2.21.",
48-
replaceWith = ReplaceWith("NewStrictNullChecks")
49-
)
5049
StrictNullChecks(enabledByDefault = false),
5150

5251
/**
@@ -80,15 +79,15 @@ enum class KotlinFeature(internal val enabledByDefault: Boolean) {
8079
* Internally, it will be the same as if [JsonSetter] (contentNulls = FAIL) had been granted.
8180
* Benchmarks show that it can check for illegal nulls with throughput nearly identical to the default (see [jackson-module-kotlin#719]).
8281
*
83-
* Note that in the new backend, the exception thrown has changed from [MissingKotlinParameterException] to [InvalidNullException].
84-
* The message will be changed accordingly.
85-
* Since 2.19, the base class of [MissingKotlinParameterException] has also been changed to [InvalidNullException],
86-
* so be careful when catching it.
87-
*
8882
* This is a temporary option for a phased backend migration,
8983
* which will eventually be merged into [StrictNullChecks].
9084
* Also, specifying both this and [StrictNullChecks] is not permitted.
9185
*/
86+
@Deprecated(
87+
level = DeprecationLevel.WARNING,
88+
message = "This option will be merged into StrictNullChecks in 2.23.",
89+
replaceWith = ReplaceWith("StrictNullChecks")
90+
)
9291
NewStrictNullChecks(enabledByDefault = false);
9392

9493
internal val bitSet: BitSet = (1 shl ordinal).toBitSet()

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ class KotlinModule private constructor(
4343
val nullToEmptyMap: Boolean = NullToEmptyMap.enabledByDefault,
4444
val nullIsSameAsDefault: Boolean = NullIsSameAsDefault.enabledByDefault,
4545
val singletonSupport: Boolean = SingletonSupport.enabledByDefault,
46-
@Suppress("DEPRECATION_ERROR")
4746
strictNullChecks: Boolean = StrictNullChecks.enabledByDefault,
4847
val kotlinPropertyNameAsImplicitName: Boolean = KotlinPropertyNameAsImplicitName.enabledByDefault,
4948
val useJavaDurationConversion: Boolean = UseJavaDurationConversion.enabledByDefault,
50-
private val newStrictNullChecks: Boolean = NewStrictNullChecks.enabledByDefault,
49+
newStrictNullChecks: Boolean = NewStrictNullChecks.enabledByDefault,
5150
) : SimpleModule(KotlinModule::class.java.name, PackageVersion.VERSION) {
5251
/*
5352
* Prior to 2.18, an older Enum called SingletonSupport was used to manage feature.
@@ -67,8 +66,6 @@ class KotlinModule private constructor(
6766
)
6867
val enabledSingletonSupport: Boolean get() = singletonSupport
6968

70-
private val oldStrictNullChecks: Boolean = strictNullChecks
71-
7269
// To reduce the amount of destructive changes, no properties will be added to the public.
7370
val strictNullChecks: Boolean = if (strictNullChecks) {
7471
if (newStrictNullChecks) {
@@ -113,7 +110,7 @@ class KotlinModule private constructor(
113110

114111
val cache = ReflectionCache(reflectionCacheSize)
115112

116-
context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, oldStrictNullChecks))
113+
context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault))
117114

118115
if (singletonSupport) {
119116
context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier)
@@ -128,7 +125,7 @@ class KotlinModule private constructor(
128125
useJavaDurationConversion
129126
))
130127
context.appendAnnotationIntrospector(
131-
KotlinNamesAnnotationIntrospector(cache, newStrictNullChecks, kotlinPropertyNameAsImplicitName)
128+
KotlinNamesAnnotationIntrospector(cache, strictNullChecks, kotlinPropertyNameAsImplicitName)
132129
)
133130

134131
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

src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/StrictNullChecksTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StrictNullChecksTest {
1616
val mapper: ObjectMapper = ObjectMapper()
1717
.registerModule(
1818
KotlinModule.Builder()
19-
.enable(KotlinFeature.NewStrictNullChecks)
19+
.enable(KotlinFeature.StrictNullChecks)
2020
.build()
2121
)
2222

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test
22

33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.databind.exc.InvalidNullException
5-
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NewStrictNullChecks
5+
import com.fasterxml.jackson.module.kotlin.KotlinFeature
66
import com.fasterxml.jackson.module.kotlin.kotlinModule
77
import com.fasterxml.jackson.module.kotlin.readValue
88
import org.junit.jupiter.api.Assertions.assertArrayEquals
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.assertThrows
1313
import kotlin.test.assertNull
1414

1515
class StrictNullChecksTest {
16-
private val mapper = ObjectMapper().registerModule(kotlinModule { enable(NewStrictNullChecks) })
16+
private val mapper = ObjectMapper().registerModule(kotlinModule { enable(KotlinFeature.StrictNullChecks) })
1717

1818
/** collection tests */
1919

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

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)