mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 15:53:46 +00:00
No new tests added because it's difficult to model a situation where a ::-access is allowed but the code throws these exceptions at runtime
30 lines
646 B
Kotlin
30 lines
646 B
Kotlin
import kotlin.reflect.IllegalAccessException
|
|
import kotlin.reflect.KMemberProperty
|
|
import kotlin.reflect.jvm.accessible
|
|
|
|
class Result {
|
|
private val value = "OK"
|
|
|
|
fun ref(): KMemberProperty<Result, String> = ::value
|
|
}
|
|
|
|
fun box(): String {
|
|
val p = Result().ref()
|
|
try {
|
|
p.get(Result())
|
|
return "Fail: private property is accessible by default"
|
|
} catch(e: IllegalAccessException) { }
|
|
|
|
p.accessible = true
|
|
|
|
val r = p.get(Result())
|
|
|
|
p.accessible = false
|
|
try {
|
|
p.get(Result())
|
|
return "Fail: setAccessible(false) had no effect"
|
|
} catch(e: IllegalAccessException) { }
|
|
|
|
return r
|
|
}
|