@CallerSensitive in Java SE 7u25

Peter Levart peter.levart at gmail.com
Tue Jun 25 10:06:20 UTC 2013


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




More information about the core-libs-dev mailing list