admin管理员组文章数量:1401673
I am working with a Java agent that is adding an annotation dynamically to a class file. When this class file is a Kotlin class, and if it is investigated by Kotlin reflection, the annotation does not become visible. If another previous annotation is added to the class, the added annotation is visible. So for the case:
@Qux
class Bar
@Retention(AnnotationRetention.RUNTIME)
annotation class Qux
everything works when I dynamically add @MyAnnotation
using the agent. But for only
class Bar
the added @MyAnnotation
cannot be seen by Kotlin reflection (but can be seen by Java reflection).
My suspicion is that this is related to kotlin.Metadata
, and indeed, the data1
property changes when an annotation is added during compilation through Kotlin. It adds two characters:
\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002**\b\u0003**\b\u0007\u0018\u00002\u00020\u0001B\u0007\u00a2\u0006\u0004\b\u0002\u0010\u0003\u00a8\u0006\u0004
The added signs are \b\u0003. I also tried Kotlin Metadata and the one change I found in the read property is that the returned instance of KotlinClassMetadata$Class
changes the contained kotlin.metadata.KmClass
's flags
from 7
to 6
when the annotation is removed during compilation.
Why would this flag change make the tool-added annotation visible or not visible. Is this a bug in Kotlin reflection? To me, this should not make a difference.
本文标签: Dynamically added annotation is not visible to Kotlin reflectionStack Overflow
版权声明:本文标题:Dynamically added annotation is not visible to Kotlin reflection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744268350a2598056.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论