RFR: 8165276: Spec states to invoke the premain method in an agent class if it's public but implementation differs [v4]
Serguei Spitsyn
sspitsyn at openjdk.java.net
Wed Dec 16 02:25:55 UTC 2020
On Wed, 16 Dec 2020 01:32:53 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> 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
More information about the serviceability-dev
mailing list