Fix ComputedField being unable to properly handle nullable types
This commit is contained in:
parent
e5d324f4fa
commit
232701b8bb
@ -1012,8 +1012,8 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
|||||||
private val codec: IStreamCodec<V>,
|
private val codec: IStreamCodec<V>,
|
||||||
private val observer: (new: V) -> Unit = {}
|
private val observer: (new: V) -> Unit = {}
|
||||||
) : AbstractField<V>(), IField<V> {
|
) : AbstractField<V>(), IField<V> {
|
||||||
private var remote: V? = null
|
private var remote: Any? = Mark
|
||||||
private var clientValue: V? = null
|
private var clientValue: Any? = Mark
|
||||||
|
|
||||||
init {
|
init {
|
||||||
observers.add(this)
|
observers.add(this)
|
||||||
@ -1024,7 +1024,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
|||||||
|
|
||||||
val value = value
|
val value = value
|
||||||
|
|
||||||
if (!isDirty && (remote == null || !codec.compare(remote ?: throw ConcurrentModificationException(), value))) {
|
if (!isDirty && (remote === Mark || !codec.compare(remote as V, value))) {
|
||||||
notifyEndpoints(this)
|
notifyEndpoints(this)
|
||||||
isDirty = true
|
isDirty = true
|
||||||
remote = codec.copy(value)
|
remote = codec.copy(value)
|
||||||
@ -1034,7 +1034,15 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val value: V
|
override val value: V
|
||||||
get() = clientValue ?: getter.invoke()
|
get() {
|
||||||
|
val clientValue = clientValue
|
||||||
|
|
||||||
|
if (clientValue === Mark) {
|
||||||
|
return getter.invoke()
|
||||||
|
} else {
|
||||||
|
return clientValue as V
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun write(stream: DataOutputStream, endpoint: Endpoint) {
|
override fun write(stream: DataOutputStream, endpoint: Endpoint) {
|
||||||
check(!isRemoved) { "Field was removed" }
|
check(!isRemoved) { "Field was removed" }
|
||||||
|
Loading…
Reference in New Issue
Block a user