Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

ClassCastException with Kotlin 1.4 and ItemViewModel #1285

Open
maroc81 opened this issue Oct 15, 2020 · 1 comment
Open

ClassCastException with Kotlin 1.4 and ItemViewModel #1285

maroc81 opened this issue Oct 15, 2020 · 1 comment

Comments

@maroc81
Copy link

maroc81 commented Oct 15, 2020

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)
@xeruf
Copy link

xeruf commented Dec 1, 2020

Since it is about version 2, it should go into the repo for that version ;) I had the same issue: edvin/tornadofx2#12

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants