On 6/23/20 23:33, Alan Bateman wrote:
On 24/06/2020 07:24, serguei.spit...@oracle.com wrote:
:
One approach would be to continue using the setAccessible and add
extra check for non-public premain method.
Something like should probably work:
if (!(Modifier.isPublic(m.getModifiers())) {
throw new IllegalAccessException("premain method is not
public");
}
The equivalent with the java launcher is:
$ java Foo.java
error: 'main' method is not declared 'public static'
$ javac Foo.java
$ java Foo
Error: Main method not found in class Foo, please define the main
method as:
public static void main(String[] args)
So have the exception message provide a helpful message will be useful
in the event that someone tries to deploy that doesn't have a public
premain method.
Thank you for the example.
Yes, I'm working on a helpful message and was thinking to use the
Reflection method:
IllegalAccessException newIllegalAccessException(Class<?> currentClass,
Class<?> memberClass,
Class<?> targetClass,
int modifiers);
BTW: Have you checked the agentmain case too?
The InstrumentationImpl::loadClassAndStartAgent() is common for both
premain and agentmain.
I'll update the CSR and my new test to cover the agentmain as well.
Thanks,
Serguei
-Alan.