Tornadofx: Inherited properties cannot be accessed via getProperty (NoSuchFieldException)

Created on 12 Jul 2016  路  4Comments  路  Source: edvin/tornadofx

TornadoFX Version: 1.5.1
Kotlin Version: 1.0.3

Define a class with an inherited property:

open class Person {
    var name = property("")
    fun nameProperty() = getProperty(Person::name)
}

class Student : Person()

and try to access the property:

Student().nameProperty()

Expected:

A StringProperty is returned.

Actual:

An exception is thrown:

java.lang.NoSuchFieldException: name$delegate
    at java.lang.Class.getDeclaredField(Class.java:2070)
    at tornadofx.PropertiesKt.getProperty(Properties.kt:24)
    ...

Culprit:

Properties.kt:24

val field = this.javaClass.getDeclaredField("${prop.name}\$delegate")

getDeclaredField only returns the fields directly declared in the class and cannot find fields of a parent class.

Most helpful comment

You never get used to how fast @edvin works :smile:

All 4 comments

Thanks for reporting this :) You are correct, there was no recursive support in the getProperty function. I have added it now, can you verify that it works for you?

Please note that your example had a typo so even with the fix you would get an error with this code:

var name = property("")

You must use the property delegate call, but I suspect you already know this and just had a typo in the example :)

var name by property("")

A response AND fix within 20 minutes of reporting the issue: I am seriously impressed right now. Thank you so much! This project is amazing :)

(You are of course right, I messed up the property declaration in the example.)

You never get used to how fast @edvin works :smile:

My pleasure @lukas-eibensteiner :) Thanks again for reporting this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pavan-p picture pavan-p  路  3Comments

Mosch0512 picture Mosch0512  路  4Comments

AlbRoehm picture AlbRoehm  路  3Comments

orochies picture orochies  路  4Comments

spkingr picture spkingr  路  4Comments