Hi Mandy,

I noticed the @CallerSensitive annotation and machinery behind it has been back-ported to JDK7. That was when one of my apps using sun.reflect.Reflection.getCallerClass(int) failed. The native method taking "int" was deprecated, but it also changed the behavior. If I run the following program:

import sun.reflect.Reflection;

public class GetCallerClassTest {

    static class Tester {
        static void test(int frames) {
System.out.println(frames + ": " + Reflection.getCallerClass(frames));
        }
    }

    public static void main(String[] args) {
        Tester.test(0);
        Tester.test(1);
        Tester.test(2);
        Tester.test(3);
    }
}


with JDK7u21, I get the following output:

0: class sun.reflect.Reflection
1: class GetCallerClassTest$Tester
2: class GetCallerClassTest
3: null


with JDK7u25, I get the following output:

0: class sun.reflect.Reflection
1: class sun.reflect.Reflection
2: class GetCallerClassTest$Tester
3: class GetCallerClassTest


It seems that with 7u25 the result is "shifted" for one calling frame. Is that behavior change intentional to encourage people to "get off that wagon"?

Regards, Peter

Reply via email to