From 7e2a2718250f02f8fb43953e5add244512610af5 Mon Sep 17 00:00:00 2001 From: Pavel Remygailo Date: Sun, 23 May 2021 11:36:23 +0300 Subject: [PATCH 1/2] Test to reproduce edvin/tornadofx#1217 --- .../testapps/TableViewCheckboxReflection.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt diff --git a/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt b/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt new file mode 100644 index 0000000..59196b2 --- /dev/null +++ b/src/test/kotlin/tornadofx/testapps/TableViewCheckboxReflection.kt @@ -0,0 +1,19 @@ +package tornadofx.testapps + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.* + +class TableViewCheckboxApp : App(TableViewCheckbox::class) + +class Model { + val booleanProperty = SimpleBooleanProperty() +} + +class TableViewCheckbox : View() { + val items = observableListOf(Model()) + + override val root = tableview(items) { + column("Checkbox", Model::booleanProperty) + .useCheckbox() + } +} From a92b4ddf85d1c46d47d994ad722f954f5456af2d Mon Sep 17 00:00:00 2001 From: Pavel Remygailo Date: Sun, 23 May 2021 11:43:56 +0300 Subject: [PATCH 2/2] Do not try to force accessibility on `Parent.getChildren` via reflection, to avoid `InaccessibleObjectException` at runtime. Fixes edvin/tornadofx#1217, edvin/tornadofx#1270, edvin/tornadofx#1276. See also: https://github.com/edvin/tornadofx/pull/964/commits/4b4f39fff28ea59ef5d0584bf7b84973ef262953 --- src/main/java/tornadofx/FX.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/tornadofx/FX.kt b/src/main/java/tornadofx/FX.kt index a2f54cc..58ca0ed 100644 --- a/src/main/java/tornadofx/FX.kt +++ b/src/main/java/tornadofx/FX.kt @@ -694,14 +694,11 @@ fun EventTarget.getChildList(): MutableList? = when (this) { } @Suppress("UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN") -private fun Parent.getChildrenReflectively(): MutableList? { - val getter = this.javaClass.findMethodByName("getChildren") - if (getter != null && java.util.List::class.java.isAssignableFrom(getter.returnType)) { - getter.isAccessible = true - return getter.invoke(this) as MutableList - } - return null -} +private fun Parent.getChildrenReflectively(): MutableList? = this.javaClass + .findMethodByName("getChildren") + ?.takeIf { java.util.List::class.java.isAssignableFrom(it.returnType) } + ?.takeIf { getter -> getter.canAccess(this) || getter.trySetAccessible() } + ?.let { getter -> getter.invoke(this) as MutableList } var Window.aboutToBeShown: Boolean get() = properties["tornadofx.aboutToBeShown"] == true