Sundararajan's Weblog

  • Java
    September 10, 2007

javac's hidden options...

Guest Author
Sorry about not writing much these days. Hoping to blog again...

Earlier, I blogged about javac's hidden option "-printflat". I modified javac source to "open up" the hidden "-printflat" flag. Well, it turns out that you don't need to do that!! As per javac source docs, there are 4 kinds of options:

  • standard public options, e.g. -classpath
  • extended public options, beginning -X, e.g. -Xlint
  • hidden options -- not public or documented, e.g. -fullversion
  • even more hidden options -- typically for debugging the compiler, beginning -XD, e.g. -XDrawDiagnostics

When I was reading javac source code, I stumbled upon "-XD" handling code in RecognizedOptions class in com.sun.tools.javac.main package. It appears that not much check is done by -XD handling code. With -XDxyz, the code puts "xyz", "xyz" as key-value pairs in compiler's options table. And with "-XDxyz=abc" the -XD handling code puts "xyz", "abc" as key-value pairs in options table. So, we can use

javac -XD-printflat Main.java

to achieve what was done my previous blog entry.
-XD-printflat would put "-printflat" in compiler's internal options table. No need to modify javac sources at all!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.