tornadofx icon indicating copy to clipboard operation
tornadofx copied to clipboard

ClassCastException with Kotlin 1.4 and ItemViewModel

Open maroc81 opened this issue 4 years ago • 1 comments

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)

maroc81 avatar Oct 15 '20 16:10 maroc81

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

xeruf avatar Dec 01 '20 09:12 xeruf