Fix IllegalAccessException on private annotation in reflection

#KT-14094 Fixed
This commit is contained in:
Alexander Udalov
2017-06-20 21:11:22 +03:00
parent fb60f4ad8f
commit 233b63469a
6 changed files with 54 additions and 1 deletions
@@ -169,7 +169,16 @@ private object ReflectClassStructure {
annotationType: Class<*>
) {
for (method in annotationType.declaredMethods) {
processAnnotationArgumentValue(visitor, Name.identifier(method.name), method(annotation)!!)
val value = try {
method(annotation)!!
}
catch (e: IllegalAccessException) {
// This is possible if the annotation class is package local. In this case, we can't read the value into descriptor.
// However, this might be OK, because we do not use any data from AnnotationDescriptor in KAnnotatedElement implementations
// anyway; we use the source element and the underlying physical Annotation object to implement the needed API
continue
}
processAnnotationArgumentValue(visitor, Name.identifier(method.name), value)
}
visitor.visitEnd()
}