@@ -15,6 +15,7 @@ import kotlin.concurrent.withLock
1515import kotlin.reflect.KType
1616import kotlin.reflect.full.isSubtypeOf
1717import kotlin.reflect.full.isSupertypeOf
18+ import kotlin.reflect.full.withNullability
1819import kotlin.reflect.typeOf
1920
2021/* *
@@ -96,7 +97,7 @@ private class DirectCompoundEntry<T : Any> private constructor(
9697 return ProviderCompoundEntry (type, this .cachedValue as R , default)
9798 } else {
9899 assert (bin != null )
99- val value: R = CBF .read(type, bin!! )
100+ val value: R = Cbf .read(type, bin!! )
100101 ? : throw AssertionError (" Serialized value is null, but $type was expected" )
101102 return ProviderCompoundEntry (type, value, default)
102103 }
@@ -116,17 +117,20 @@ private class DirectCompoundEntry<T : Any> private constructor(
116117
117118 @OptIn(UncheckedApi ::class )
118119 override fun get (type : KType ): T {
120+ val type = type.withNullability(false )
121+
119122 if (this .type != null && this .cachedValue != null ) {
120123 if (! type.isSupertypeOf(this .type!! ))
121124 throw IllegalArgumentException (" $type (return type) is not a supertype of ${this .type} (entry type)" )
122125 return this .cachedValue as T
123126 } else {
124127 assert (bin != null )
125128
126- this .type = type
127- this .cachedValue = CBF .read(type, bin!! )
128- ? : throw AssertionError (" Serialized value is null, but $type was expected" )
129- this .bin = null
129+ set(
130+ type.withNullability(false ),
131+ Cbf .read(type, bin!! )
132+ ? : throw AssertionError (" Serialized value is null, but $type was expected" )
133+ )
130134
131135 return this .cachedValue!!
132136 }
@@ -135,7 +139,7 @@ private class DirectCompoundEntry<T : Any> private constructor(
135139 @OptIn(UncheckedApi ::class )
136140 override fun serialize (): ByteArray? {
137141 if (type != null && cachedValue != null ) {
138- return CBF .write(type!! , cachedValue)
142+ return Cbf .write(type!! , cachedValue)
139143 } else {
140144 return bin
141145 }
@@ -156,7 +160,7 @@ private class DirectCompoundEntry<T : Any> private constructor(
156160 } else {
157161 // no type check possible
158162 assert (bin != null )
159- val value = CBF .read<T >(entry.type, bin!! )
163+ val value = Cbf .read<T >(entry.type, bin!! )
160164 ? : throw AssertionError (" Serialized value is null, but $type was expected" )
161165 entry.set(entry.type, value)
162166 }
@@ -201,7 +205,7 @@ private class ProviderCompoundEntry<T>(
201205
202206 @OptIn(UncheckedApi ::class )
203207 override fun serialize (): ByteArray? {
204- return cachedValue?.let { CBF .write(type, it) }
208+ return cachedValue?.let { Cbf .write(type, it) }
205209 }
206210
207211 override fun transferTo (entry : CompoundEntry <T >) {
@@ -221,7 +225,7 @@ private class ProviderCompoundEntry<T>(
221225}
222226
223227/* *
224- * A compound is a key-value storage intended for serialization via [CBF ].
228+ * A compound is a key-value storage intended for serialization via [Cbf ].
225229 *
226230 * After deserialization, a [Compound] contains only binary data of values of unknown types
227231 * (and the keys under which they're stored), which is then lazily deserialized
@@ -264,7 +268,7 @@ class Compound private constructor(
264268 when (entry) {
265269 is DirectCompoundEntry <T > -> {
266270 if (value != null ) {
267- entry.set(type, value)
271+ entry.set(type.withNullability( false ) , value)
268272 } else {
269273 entryMap - = key
270274 }
@@ -273,7 +277,7 @@ class Compound private constructor(
273277 is ProviderCompoundEntry <T > -> entry.set(type, value)
274278 null -> {
275279 if (value != null ) {
276- entryMap[key] = DirectCompoundEntry (type, value)
280+ entryMap[key] = DirectCompoundEntry (type.withNullability( false ) , value)
277281 }
278282 }
279283 }
@@ -434,11 +438,11 @@ class Compound private constructor(
434438 }
435439
436440 /* *
437- * Creates a deep copy of this compound, copying all deserialized values using [CBF .copy].
441+ * Creates a deep copy of this compound, copying all deserialized values using [Cbf .copy].
438442 */
439443 @OptIn(UncheckedApi ::class )
440444 fun copy (): Compound = lock.withLock {
441- copy { type, obj -> CBF .copy(type, obj) }
445+ copy { type, obj -> Cbf .copy(type, obj)!! }
442446 }
443447
444448 /* *
0 commit comments