Marco Signoretto
09/02/2020, 12:27 PM.class
. The interface I want to read the metadata from is
interface PippoSample {
fun showRandom(): Boolean
fun sayHi()
fun sayHiWith(param: String)
}
if I run javap -v PippoSample.class
I can see that the metadata is present into the .class
:
Last modified Sep 2, 2020; size 682 bytes
MD5 checksum 6aed5c3b65bca7ea5739b7d8f2638920
Compiled from "PippoSample.kt"
public interface com.careem.mockingbird.samples.PippoSample
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
Constant pool:
#1 = Utf8 com/careem/mockingbird/samples/PippoSample
#2 = Class #1 // com/careem/mockingbird/samples/PippoSample
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 showRandom
#6 = Utf8 ()Z
#7 = Utf8 this
#8 = Utf8 Lcom/careem/mockingbird/samples/PippoSample;
#9 = Utf8 sayHi
#10 = Utf8 ()V
#11 = Utf8 sayHiWith
#12 = Utf8 (Ljava/lang/String;)V
#13 = Utf8 Lorg/jetbrains/annotations/NotNull;
#14 = Utf8 param
#15 = Utf8 Ljava/lang/String;
#16 = Utf8 Lkotlin/Metadata;
#17 = Utf8 mv
#18 = Integer 1
#19 = Integer 16
#20 = Utf8 bv
#21 = Integer 0
#22 = Integer 3
#23 = Utf8 k
#24 = Utf8 d1
#25 = Utf8 \n\n\n\n\\n\n\n
\f200H&J020H&H&¨\t
#26 = Utf8 d2
#27 = Utf8
#28 = Utf8 samples
#29 = Utf8 PippoSample.kt
#30 = Utf8 RuntimeInvisibleParameterAnnotations
#31 = Utf8 SourceFile
#32 = Utf8 RuntimeVisibleAnnotations
{
public abstract boolean showRandom();
descriptor: ()Z
flags: ACC_PUBLIC, ACC_ABSTRACT
public abstract void sayHi();
descriptor: ()V
flags: ACC_PUBLIC, ACC_ABSTRACT
public abstract void sayHiWith(java.lang.String);
descriptor: (Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_ABSTRACT
RuntimeInvisibleParameterAnnotations:
0:
0: #13()
}
SourceFile: "PippoSample.kt"
RuntimeVisibleAnnotations:
0: #16(#17=[I#18,I#18,I#19],#20=[I#18,I#21,I#22],#23=I#18,#24=[s#25],#26=[s#8,s#27,s#9,s#27,s#11,s#14,s#27,s#5,s#27,s#28])
Then from code I want to read the metadata information, I was doing the following:
val file = File("<long_path>/build/classes/kotlin/jvm/main")
val url = file.toURI().toURL()
val urls = arrayOf(url)
val cl = URLClassLoader(urls)
val externalClass = cl.loadClass("com.careem.mockingbird.samples.PippoSample")
println(externalClass.getAnnotation(Metadata::class.java))
But I got null
in the printed values. If I add other annotations on the interface I'll get them but no way I get the @Metadata
. Anyone can help?