Skip to content

Commit

Permalink
Do not try to force accessibility on Parent.getChildren via reflect…
Browse files Browse the repository at this point in the history
…ion,

to avoid `InaccessibleObjectException` at runtime.

Fixes edvin/tornadofx#1217, edvin/tornadofx#1270, edvin/tornadofx#1276.

See also: edvin/tornadofx@4b4f39f
  • Loading branch information
pavlus committed May 23, 2021
1 parent 7e2a271 commit a92b4dd
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/tornadofx/FX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,11 @@ fun EventTarget.getChildList(): MutableList<Node>? = when (this) {
}

@Suppress("UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN")
private fun Parent.getChildrenReflectively(): MutableList<Node>? {
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<Node>
}
return null
}
private fun Parent.getChildrenReflectively(): MutableList<Node>? = 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<Node> }

var Window.aboutToBeShown: Boolean
get() = properties["tornadofx.aboutToBeShown"] == true
Expand Down

0 comments on commit a92b4dd

Please sign in to comment.