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

Jan Lahoda jlahoda at openjdk.org
Wed Nov 29 12:31:18 UTC 2023


On Fri, 10 Nov 2023 13:30:10 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> 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...

This pull request has now been integrated.

Changeset: 65dfcae6
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/65dfcae6d6c11e8dcb807a2559278fb082e095b9
Stats:     128 lines in 23 files changed: 73 ins; 9 del; 46 mod

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

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list