tornadofx
tornadofx copied to clipboard
ClassCastException with Kotlin 1.4 and ItemViewModel
I ran into the following ClassCastException with Kotlin 1.4 and an ItemViewModel.
java.lang.ClassCastException: class tornadofx.BindingAwareSimpleDoubleProperty cannot be cast to class javafx.beans.property.ObjectProperty
It seems the new type interference algorithm chooses different types when binding compared to Kotlin 1.3.
An example to reproduce the exception:
import tornadofx.*
class LimitsConfigTestView : View("Limits Configuration") {
private val limits = LimitsTest()
private val viewmodel = LimitsTestViewModel(limits)
override val root = vbox {
form {
fieldset {
field {
textfield() {
bind(viewmodel.errorMaxSpeed)
}
}
}
}
}
}
class LimitsTest {
var errorMaxSpeed: Double by property(0.0)
fun errorMaxSpeedProperty() = getProperty(LimitsTest::errorMaxSpeed)
}
class LimitsTestViewModel(limits: LimitsTest) : ItemViewModel<LimitsTest>(limits) {
val errorMaxSpeed = bind(LimitsTest::errorMaxSpeedProperty)
}
With kotlin 1.3, the bind in the view model is inferred as
bind<Double, Property<Double>, Property<Double>>(LimitsTest::errorMaxSpeedProperty)
while kotlin 1.4 infers as
bind<Double, ObjectProperty<Double>, ObjectProperty<Double>>(LimitsTest::errorMaxSpeedProperty)
Details: TornadoFX: no.tornado:tornadofx:2.0.0-SNAPSHOT Kotlin: 1.4.10 JVM:
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)
Since it is about version 2, it should go into the repo for that version ;) I had the same issue: https://github.com/edvin/tornadofx2/issues/12