Files
kotlin/compiler/testData/codegen/boxWithStdlib/reflection/properties/privateClassVar.kt
Alexander Udalov ef4a5e78ed Catch IllegalAccessException in KFunction.call
Rename IllegalPropertyAccessException -> IllegalCallableAccessException
2015-07-29 21:36:51 +03:00

31 lines
629 B
Kotlin
Vendored

import kotlin.reflect.*
import kotlin.reflect.jvm.isAccessible
class A {
private var value = 0
fun ref() = A::class.memberProperties.single() as KMutableProperty1<A, Int>
}
fun box(): String {
val a = A()
val p = a.ref()
try {
p.set(a, 1)
return "Fail: private property is accessible by default"
} catch(e: IllegalCallableAccessException) { }
p.isAccessible = true
p.set(a, 2)
p.get(a)
p.isAccessible = false
try {
p.set(a, 3)
return "Fail: setAccessible(false) had no effect"
} catch(e: IllegalCallableAccessException) { }
return "OK"
}