Fix IllegalAccessException on private annotation in reflection
#KT-14094 Fixed
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation private class Ann(val name: String)
|
||||
|
||||
class A {
|
||||
@Ann("OK")
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ann = A::class.members.single { it.name == "foo" }.annotations.single() as Ann
|
||||
return ann.name
|
||||
}
|
||||
+6
@@ -13843,6 +13843,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateAnnotation.kt")
|
||||
public void testPrivateAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/privateAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessors.kt")
|
||||
public void testPropertyAccessors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/propertyAccessors.kt");
|
||||
|
||||
@@ -13843,6 +13843,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateAnnotation.kt")
|
||||
public void testPrivateAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/privateAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessors.kt")
|
||||
public void testPropertyAccessors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/propertyAccessors.kt");
|
||||
|
||||
@@ -13843,6 +13843,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateAnnotation.kt")
|
||||
public void testPrivateAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/privateAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessors.kt")
|
||||
public void testPropertyAccessors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/propertyAccessors.kt");
|
||||
|
||||
+10
-1
@@ -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()
|
||||
}
|
||||
|
||||
+12
@@ -15667,6 +15667,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("privateAnnotation.kt")
|
||||
public void testPrivateAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/privateAnnotation.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessors.kt")
|
||||
public void testPropertyAccessors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/annotations/propertyAccessors.kt");
|
||||
|
||||
Reference in New Issue
Block a user