lundi 15 février 2021

Why is a setter for public field private on certain devices?

I have a public field and I pass a reference to its setter to a method. Certain devices crash when accessing this setter.

Minimal example

var isDurationValid = false

fun onHoursSet(hours: Int) {
    evaluate(hours, ::isDurationValid.setter)
}

fun evaluate(hours: Int, setter: (Boolean) -> Unit) {
    setter.invoke(hours > 0 && hours < 24)
}

I have the following exception report on crash analytics on certain devices:

java.lang.IllegalAccessException: Class java.lang.Class<kotlin.reflect.jvm.internal.calls.CallerImpl$FieldSetter$BoundInstance> cannot access private field





Aucun commentaire:

Enregistrer un commentaire