JDK-8003350 : javac -target does not work without -source
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2012-11-13
  • Updated: 2012-11-26
  • Resolved: 2012-11-14
Related Reports
Relates :  
Description
Create simple Test.java
public class Test {
  public static void main(String[] args) {
  }
} 

Have JDK 7 installed
try javac -target 1.6 Test.java
FAIL: javac: target release 1.6 conflicts with default source release 1.7

try javac -target 1.6 -source 1.6 Test.java
Success.

The same when you try to use -target 1.5 or -target 1.4.2
Comments
The recommended practice has long been to explicitly set the -source, -target, and -encoding options of javac: "Build Advice: Set Source, Target, and Encoding," https://blogs.oracle.com/darcy/entry/build_advice_set_source_target The JDK build now follows this practice too. In JDK 7, setting an older source version without setting the bootclasspath, a warning is issued: "New javac warning for setting an older source without bootclasspath," https://blogs.oracle.com/darcy/entry/bootclasspath_older_source It may be human to emit a different error message in the situation described in this bug, "FAIL: javac: target release 1.6 conflicts with default source release 1.7; use the -source option to select an appropriate release." but that is a RFE and not a bug. More on default source and target values: "Source, target, class file version decoder ring," https://blogs.oracle.com/darcy/entry/source_target_class_file_version
26-11-2012

javac is behaving as intended: there is no bug here, and we will not change javac behavior, This issue is Closed. We cannot be responsible for (mis)information on random websites found by Google searches If you want to continue this, please file a docs bug against the documentation -- but note that the docs team will not probably change the docs on existing releases, and cannot change info on non-Oracle websites.
24-11-2012

I just did what user will do: I got an error saying "javac: target release 1.5 conflicts with default source release 1.7" Simply printed this string into Google search from and got results. Let's see at the two highest: http://www.madewithmarmalade.com/devnet/forum/javac-target-release-15-conflicts-default-source-release-17-8 http://forum.mulesoft.org/mulesoft/topics/target_release_1_5_conflicts_with_default_source_release_1_7 There is a complain and answer that user should move back to JDK 6. I want to say that the decision with JDK 7 is not clear for users. And some of the choose moving back JDK 6. Of course we should not change the behaviour of JDK 7 now but we need to think how to let them easily find the right answer. I've looked at the javac man page. It is never directly said that -target 1.5 will not work without -source. It is not so clear even if you read carefully.
23-11-2012

It has /always/ been the case that you could never use a -target version lower than the source version, whether the source version is provided explicitly or explicitly. Where have you seen "complaints"? Why would people not want to use JDK 7 because of this? For those people that are surprised by the behavior, the workaround is trivial: either use both -source and -target, or use neither. For those people that need details, see the javac man page: http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html
16-11-2012

Form the user point of view there is a new behaviour from JDK 6 to JDK 7. Do we have it documented? I've seen a lot of complains from user all over Internet. And such change forced them to move back to JDK 6 since they did not know about the change.
16-11-2012

In JDK 6, the default language level was 5, because there were no significant language changes. So you could specify -target 5 or -target 6 without needing to change -source. The usage message is not the place to add this level of detail about the inter-relationships between options. It should be covered on the man pages for the tool
14-11-2012

Why the behaviour for javac and javac 6 differs ? JDK6_HOME/bin/javac -target 1.5 Test.java works fine when JDK7_HOME/bin/javac -target 1.5 Test.java FAILs Looks like train to train regression. At the same time if we look at the help printout of the javac there is nothing in -target section saying that -source should be used. So help message at least confusing.
14-11-2012

Not a bug, this is the expected behavior. If you want to down-rev the -target value from the default, you must also down-rev the -source value.
14-11-2012

Workaround is mentioned in the description. -target may be used together with -source
13-11-2012