RFR: 8311500: StackWalker.getCallerClass() can throw if invoked reflectively [v2]

Volker Simonis simonis at openjdk.org
Thu Jul 6 08:00:54 UTC 2023


On Wed, 5 Jul 2023 19:14:07 GMT, Mandy Chung <mchung at openjdk.org> wrote:

> Thanks for catching this issue. I agree that `Method::invoke` should be skipped the caller-sensitive test in this case but the fix isn't quite right. The caller-sensitive test should apply in any batch. For example, `CSM` calls `getCallerClass` reflectively, I think the stack would look like this:
> 
> ```
> java.lang.StackWalker::getCallerClass
> java.lang.invoke.DirectMethodHandle$Holder::invokeStatic
> java.lang.invoke.LambdaForm$MH/0x0000000800002c00::invoke
> :
> :
> jdk.internal.reflect.DirectMethodHandleAccessor::invokeImpl
> jdk.internal.reflect.DirectMethodHandleAccessor::invoke
> java.lang.reflect.Method::invoke
> CSM  <--------- caller-sensitive method and UOE should be thrown
> ```
> 
> In this case, UOE should be thrown.

Hi @mlchung ,
Thanks for your comments. I think you're right. More specifically, the caller-sensitive test should be applied to the first non-reflective, non-methodhandle frame, independent on the batch in which it appears.

I'll add a new test for the case you've brought up and update the fix accordingly.

Best regards,
Volker

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14773#issuecomment-1623171029


More information about the core-libs-dev mailing list