Review Request: JDK-8157464: StackWalker.getCallerClass() is not
mandy.chung at oracle.com
Tue Sep 13 18:24:04 UTC 2016
This revises the proposal posted some time ago .
StackWalker::getCallerClass is a convenient method to find the caller class. It will return the invoker of the MethodHandle and java.lang.reflect.Method for the method calling StackWalker::getCallerClass, as it’s currently specified.
This issue is related to MethodHandle for @CallerSensitive method. It behaves as if the caller is the lookup class and in the current implementation, the actual caller class is not the lookup class but a generated class.
One intended usage of StackWalker::getCallerClass is to be called by library code acting as an agent that calls @CallerSensitive method on behalf of the true caller and typically it will call an appropriate method with the appropriate parameter (e.g. ResourceBundle.getBundle(String, ClassLoader).
Given that StackWalker::getCallerClass is not expected to be used by any @CS method, this patch proposes to catch and throw an exception if StackWalker::getCallerClass is called by a @CS method. This will allow time to revisit this when such need is identified.
More information about the core-libs-dev