15 RFR(XS): 8165276: Spec states that invoke the premain method in an agent class if it's public but implementation differs
    Alan Bateman 
    Alan.Bateman at oracle.com
       
    Wed Jun 24 06:33:12 UTC 2020
    
    
  
On 24/06/2020 07:24, serguei.spitsyn at 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.
BTW: Have you checked the agentmain case too?
-Alan.
    
    
More information about the serviceability-dev
mailing list