RFR: 8308399: Recommend --release when -source and -target are misused

Jan Lahoda jlahoda at openjdk.org
Fri Nov 10 13:36:11 UTC 2023


This patch modifies some warning and error messages to recommend `--release` more loudly. Please see details below.

Note that while the patch changes `compiler.warn.source.target.conflict` to `compiler.err.source.target.conflict`, there is no change in the set of accepted options and their combinations. This used to behave as an error, and still behaves as an error. So this patch only changes the console text from `warning: ...` to `error: ...`.


+ javac -source 8 /tmp/Test.java
warning: [options] bootstrap class path is not set in conjunction with -source 8
  not setting the bootstrap class path may lead to class files that cannot run on JDK 8
    --release 8 is recommended instead of -source 8 because it sets the bootstrap class path automatically
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings



+ javac -source 8 -target 8 /tmp/Test.java
warning: [options] bootstrap class path is not set in conjunction with -source 8
  not setting the bootstrap class path may lead to class files that cannot run on JDK 8
    --release 8 is recommended instead of -source 8 -target 8 because it sets the bootstrap class path automatically
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
4 warnings



+ javac -source 11 /tmp/Test.java
warning: [options] location of system modules is not set in conjunction with -source 11
  not setting the location of system modules may lead to class files that cannot run on JDK 11
    --release 11 is recommended instead of -source 11 because it sets the location of system modules automatically
1 warning



+ javac -source 11 -target 11 /tmp/Test.java
warning: [options] location of system modules is not set in conjunction with -source 11
  not setting the location of system modules may lead to class files that cannot run on JDK 11
    --release 11 is recommended instead of -source 11 -target 11 because it sets the location of system modules automatically
1 warning



+ javac -target 17 -source 11 /tmp/Test.java
warning: [options] location of system modules is not set in conjunction with -source 11
  not setting the location of system modules may lead to class files that cannot run on JDK 11
    --release 11 is recommended instead of -source 11 -target 17 because it sets the location of system modules automatically
1 warning



+ javac -target 8 -source 11 /tmp/Test.java
error: specified target release 8 is too old for the specified source release 11
  --release 8 is recommended when compiling code to run on JDK 8



+ javac -target 8 /tmp/Test.java
error: specified target release 8 is too old for the default source release 22
  --release 8 is recommended when compiling code to run on JDK 8

-------------

Commit messages:
 - Fixing test.
 - Fixing tests.
 - 8308399: Recommend --release when -source and -target are misused

Changes: https://git.openjdk.org/jdk/pull/16612/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16612&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8308399
  Stats: 128 lines in 23 files changed: 73 ins; 9 del; 46 mod
  Patch: https://git.openjdk.org/jdk/pull/16612.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16612/head:pull/16612

PR: https://git.openjdk.org/jdk/pull/16612


More information about the compiler-dev mailing list