Good catch, Peter. I file an issue and https://bugs.openjdk.java.net/browse/JDK-8160698
Will send out a webrev next. Mandy > On Jun 29, 2016, at 11:32 PM, Peter Levart <[email protected]> wrote: > > Hi Mandy, > > I'm sorry I haven't noticed this RFR before. Note that as currently > implemented, --dry-run does not prevent user code to be executed in all > cases. For example, the following test: > > public class Test { > static { > System.out.println("Hello from <clinit>"); > } > public static void main(String[] args) { > System.out.println("Hello from main()"); > } > } > > ...when run with: "java -cp . Test", produces the following: > > Hello from <clinit> > Hello from main() > > ...but when run with: "java --dry-run -cp . Test", it still produces the > following: > > Hello from <clinit> > > > In order to prevent user code from being executed, main class should not be > initialized. But is it possible to check for the presence of a method in a > class without initializing it? Maybe the check for the presence of main > method could simply be dropped out of --dry-run? > > Regards, Peter > > > On 06/24/2016 03:49 PM, Mandy Chung wrote: >> Webrev: >> http://cr.openjdk.java.net/~mchung/jdk9/webrevs/8159596/webrev.00/ >> >> `java --dry-run` will create the VM, load the main, locate the static void >> main method, and exit (with 0) instead of executing the method. As all >> module options are processed and the boot layer is created, this would be >> useful to sanity check the options and detect possible issues. >> >> Mandy >> >
