Reflection.getCallerClass(n) does not skip reflection calls in constructors

Weijun Wang weijun.wang at oracle.com
Sun Nov 25 21:46:24 PST 2012


Hi

I'm trying to use Reflection.getCallerClass(n) to find out who is 
calling a method. The method's spec says:

                                      .... Frames associated with
     java.lang.reflect.Method.invoke() and its implementation are
     completely ignored and do not count toward the number of "real"
     frames skipped.

This is very nice but it does not mention Constructor.newInstance(). In 
fact, I do see the following entries if I'm creating an object thru 
reflection:

    Callee
    class sun.reflect.NativeConstructorAccessorImpl
    class sun.reflect.NativeConstructorAccessorImpl
    class sun.reflect.DelegatingConstructorAccessorImpl
    class java.lang.reflect.Constructor
    Caller

Is there any reason why we cannot do the same for constructor instantiation?

Thanks
Max


More information about the hotspot-dev mailing list