W metodzie statycznej (opatrzone @CallerSensitive
) staram się uzyskać nazwę klasy wywołującego:java.lang.InternalError: CallerSensitive adnotacja oczekuje na ramie 1
@CallerSensitive
public static void someMethod() {
String name = sun.reflect.Reflection.getCallerClass().getName();
...
}
pojawia się błąd:
java.lang.InternalError: CallerSensitive annotation expected at frame 1
Co jest nie tak?
Odniesienia
UPDATE
ja pomocą javy 8 (U25) oraz metodę getCallerClass()
jest nie przestarzałe (getCallerClass(int)
nie jest zalecany), jak można zaobserwować po demontażu bajtowego:
$ /usr/lib/jvm/java-8-oracle/bin/javap -cp /usr/lib/jvm/java-8-oracle/jre/lib/rt.jar -verbose sun.reflect.Reflection > bytecode
wyjścia (tylko odpowiednie linie są przedstawione)
Classfile jar:file:/usr/lib/jvm/jdk1.8.0_25/jre/lib/rt.jar!/sun/reflect/Reflection.class
Last modified Sep 17, 2014; size 6476 bytes
Compiled from "Reflection.java"
public class sun.reflect.Reflection
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#78 = Utf8 Lsun/reflect/CallerSensitive;
#80 = Utf8 Deprecated
#82 = Utf8 Ljava/lang/Deprecated;
{
public sun.reflect.Reflection();
descriptor:()V
flags: ACC_PUBLIC
public static native java.lang.Class<?> getCallerClass();
descriptor:()Ljava/lang/Class;
flags: ACC_PUBLIC, ACC_STATIC, ACC_NATIVE
Signature: #76 //()Ljava/lang/Class<*>;
RuntimeVisibleAnnotations:
0: #78()
public static native java.lang.Class<?> getCallerClass(int);
descriptor: (I)Ljava/lang/Class;
flags: ACC_PUBLIC, ACC_STATIC, ACC_NATIVE
Deprecated: true
Signature: #81 // (I)Ljava/lang/Class<*>;
RuntimeVisibleAnnotations:
0: #82()
co java używasz? Zgodnie z dokumentami, które łączyłeś, getCallerClass() został wycofany i jest usuwany. –
Dzięki! Zobacz moje zaktualizowane pytanie – rmuller