Musings on JDK development

  • Java
    December 22, 2010

New javac warning for setting an older source without bootclasspath

To use javac from JDK N to cross-compiler to an older platform version, the correct practice is to:

  • Use the older -source setting.
  • Set the bootclasspath to compile against the rt.jar (or equivalent) for the older platform.

If the second step is not taken, javac will dutifully use the old language rules combined with new libraries, which can result in class files that do not work on the older platform since references to non-existent methods can get included.

Thanks to work by Jon Gibbons, in JDK 7 build 121 and later javac detects and warns about this suspicious situation; for example:

$ javac -source 6 HelloWorld.java
warning: [options] bootstrap class path not set in conjunction with -source 1.6

One way to address the warning is to set the bootclasspath. If that is inappropriate, the warning can be disabled with a new suboption within the -Xlint family, -Xlint:-options.

With this change, a likely problematic combination of options to javac that can lead to subtle build errors are diagnosed by the compiler and can easily by either directly addressed, or documented as part of the build process via the new -Xlint suboption.

Join the discussion

Comments ( 5 )
  • whatsthebeef Wednesday, December 22, 2010

    I like the small and concise snippets of information about new features.

    It's a great way to keep up to spped with the jdk as well as learn aspects of the language which are shielded from by using certain IDEs

    Is there any other interesting sources of information (blogs, announcements etc..) you know of with a similar format

  • Joe Darcy Thursday, December 23, 2010


    Besides the blogs.sun.com tag stream for JDK 7:


    Alex Miller has a feed of JDK 7 links:


    And many of Dalibor's OpenJDK tweets related to JDK 7:


  • Jevgeni Kabanov Saturday, December 25, 2010

    Isn't this setting misleading? Setting the bootclasspath will work when a new method is added, but if a new class has been added (e.g. StringBuilder), it will still be found from the newer rt.jar. I feel that doing this instead of building on the actual older JDK gives a false sense of security, without ensuring compatibility.

  • Joe Darcy Monday, December 27, 2010


    Setting the bootclasspath option of javac is exactly the option which prevents javac from looking for (and finding) new classes, such as StringBuilder in the rt.jar (or equivalent) on the current platform.

    Building on an older JDK works too of course.

  • Andrea Wednesday, December 5, 2018

    1° javac Mioprg.java ---> java Mioprg (NOT RUN!)
    2° javac -source 8 Mioprg.java ---> java Mioprg (NOT RUN!)
    3° javac -source 7 Mioprg.java ---> java Mioprg (NOT RUN!)

    The message is ... Mioprg has been compiled...version 55.0 java runtime only recognizes.. 52.0

    in all cases.

    What i do?
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.