On Wed, 16 Dec 2020 01:32:53 GMT, Serguei Spitsyn <[email protected]> wrote:
>> The agent class doesn't have to be public it just has to be accessible.
>>
>> The premain method should be queried for public modifier rather than just
>> relying on a failed invocation request.
>
> David, thank you for catching this. I'm probably missing something here.
> If the agent class is not public then the `m.canAccess(null)` check is not
> passed and IAE is thrown with the message:
> `Exception in thread "main" java.lang.IllegalAccessException: method
> NonPublicAgent.premain must be declared public`
>
> But the `NonPublicAgent.premain` is declared public as below:
> public static void premain(String agentArgs, Instrumentation inst) {
> System.out.println("premain: NonPublicAgent was loaded");
> }
> It seems, the IAE is thrown because the agent class is not public.
> Does it mean the `m.canAccess(null)` check is not fully correct?
Thanks, David!
Yes, I was also thinking that the setAccessible has to be remained after all
the checks.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1694