Changing Sources and Moving Targets: Evolving the javac command line

As written up in JEP 182: Policy for Retiring javac -source and -target Options, we're implementing a policy to over time clean up the -source and -target portions of javac's command line:

  • Class files going all the way back to version 45.3 generated by JDK 1.0.2 will continue to be recognized by javac when put on the classpath, etc.
  • The never-documented -target options 1.4.1, 1.4.2, and jsr14 have been removed in JDK 8 (8010179).
  • In JDK 8, source and target options for 1.5 and below will be deprecated and a warning will be printed on their use (8011043).
  • In JDK 9, source and target options for 1.5 and below will be removed (8011044).
  • Starting in JDK 9, a "one plus three back" policy will apply to source and target options. JDK 9 will support (9/1.9, 8/1.8, 7/1.7, 6/1.6) and JDK 10 will support (10/1.10, 9/1.9, 8/1.8, 7/1.7) and so on.

Removing support for the old options will ease compiler maintenance in several ways. First, there will be direct benefits from allowing some code to be deleted. Nixing jsr14 allowed about 250 lines of code to be excised. Second, fewer interactions between new language features and old source levels need to be handled in the compiler. The Java Language Specification only deals with a single version of the language and there is no formal specification of many aspects of how a Java compiler is supposed to behave. To use a recent example, there is no specification for how a new-in-8 default method being introduced to the language and core libraries by Project Lambda should appear to code being compiled under, say, -source 6. Limiting the span of source and target version supported reduces the need to define such cross-version interactions. (The practical impact of source cross-version interfaces would be greatly reduced if developers more often follwed the recommended practice of setting the bootclasspath when cross-compiling to an older platform version.)

This policy will help balance stability versus progress and should cover releases having public updates when a new JDK is released.

Comments:

I found in http://stackoverflow.com/questions/9260448/which-jdks-distributions-can-run-javac-source-1-6-target-1-5 that javac in Oracle based Java distributions (OpenJDK/Oracle) does not support "-source 1.6 -target 1.5" (and presumably all other combinations where the source level is different from the target level). This is interesting to us, because the Maven compiler plugin specify both to javac.

I would like to hear if this will be looked at in Java 8 (or later)?

Posted by Thorbjørn Ravn Andersen on June 29, 2013 at 06:12 PM PDT #

@Thorbjørn,

In general, javac requires that target >= source. One reason for this is that the generated code for constructs in source level N may rely on libraries only present in version N and later. The javac man page has more details on the relationship between the source and target options:

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html

Since source 1.5 and source 1.6 are treated nearly identically in javac, the only difference is that sourcde 1.6 treats file encoding issues as errors, I recommend in your use case to use source 1.5 / target 1.5.

HTH

Posted by guest on June 29, 2013 at 07:24 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

darcy

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News

No bookmarks in folder

Blogroll