Java 11 was released yesterday. 1) The first patch adds support for this Java version to the 'javacomp-script' and 'javacomp' modules.
With it, the config.log output in gettext-tools, when run in an environment with Java 11 in the $PATH, changes from ========================= BEFORE ========================= configure:6578: CLASSPATH=. java conftestver configure:6585: WARNING: unknown target-version 11, please update gt_JAVACOMP macro configure:6638: checking for Java compiler configure:6884: found /usr/local/java/jdk-11/bin/javac configure:7030: javac -d . conftest.java configure:7059: javac -target 1.1 -d . conftest.java warning: target release 1.1 conflicts with default source release 11 configure:7088: javac -target 1.1 -source 1.5 -d . conftest.java warning: source release 1.5 requires target release 1.5 configure:7125: result: no to ========================= AFTER ========================= configure:6578: CLASSPATH=. java conftestver configure:6641: checking for Java compiler configure:6887: found /usr/local/java/jdk-11/bin/javac configure:7033: javac -d . conftest.java configure:7040: javac -source 1.6 -d . conftest.java warning: [options] bootstrap class path not set in conjunction with -source 6 warning: [options] source value 6 is obsolete and will be removed in a future release warning: [options] To suppress warnings about obsolete options, use -Xlint:-options. 3 warnings configure:7045: javac -d . conftestfail.java configure:7049: javac -source 1.6 -d . conftestfail.java warning: [options] bootstrap class path not set in conjunction with -source 6 warning: [options] source value 6 is obsolete and will be removed in a future release warning: [options] To suppress warnings about obsolete options, use -Xlint:-options. conftestfail.java:1: error: strings in switch are not supported in -source 6 class conftestfail { void foo () { switch ("A") {} } } ^ (use -source 7 or higher to enable strings in switch) 1 error 3 warnings configure:7128: result: javac -source 1.6 2) With this new version, the rapid release cycles continue. In order to not have Java 12 and then Java 13 etc. rejected by the two modules, let me add code that accepts these new versions using minimal assumptions. When such a Java version gets found, we continue to use "-source 1.6" etc., as if it were version 11. With just this patch alone and without the first patch, the gettext-tools config.log changes from ========================= BEFORE ========================= configure:6578: CLASSPATH=. java conftestver configure:6585: WARNING: unknown target-version 11, please update gt_JAVACOMP macro configure:6638: checking for Java compiler configure:6884: found /usr/local/java/jdk-11/bin/javac configure:7030: javac -d . conftest.java configure:7059: javac -target 1.1 -d . conftest.java warning: target release 1.1 conflicts with default source release 11 configure:7088: javac -target 1.1 -source 1.5 -d . conftest.java warning: source release 1.5 requires target release 1.5 configure:7125: result: no to ========================= AFTER ========================= configure:6578: CLASSPATH=. java conftestver configure:6639: checking for Java compiler configure:6885: found /usr/local/java/jdk-11/bin/javac configure:7031: javac -d . conftest.java configure:7060: javac -target 10 -d . conftest.java warning: target release 10 conflicts with default source release 11 configure:7089: javac -target 10 -source 1.6 -d . conftest.java warning: [options] bootstrap class path not set in conjunction with -source 6 warning: [options] source value 6 is obsolete and will be removed in a future release warning: [options] To suppress warnings about obsolete options, use -Xlint:-options. 3 warnings configure:7126: result: javac -target 10 -source 1.6 Of course, there is a certain risk that the assumptions won't hold. Let's see.
>From bd09403f71a792b4e5c482c7ebb29d26c129dbe6 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 26 Sep 2018 11:21:30 +0200 Subject: [PATCH 1/2] javacomp-script, javacomp: Add support for Java 11. * m4/javacomp.m4 (gt_JAVACOMP): Accept source-version 11 and target-version 11. * lib/javaversion.h: Update comments. * lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND, source_version_index, get_goodcode_snippet, get_failcode_snippet, TARGET_VERSION_BOUND, target_version_index, corresponding_classfile_version): Accept source_version 11 and target_version 11. * lib/javacomp.h: Update comments accordingly. --- ChangeLog | 13 +++++++++++++ lib/javacomp.c | 23 ++++++++++++++++------- lib/javacomp.h | 5 ++++- lib/javaversion.h | 2 +- m4/javacomp.m4 | 21 ++++++++++++++++++--- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 904a518..3dad3ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-09-26 Bruno Haible <br...@clisp.org> + + javacomp-script, javacomp: Add support for Java 11. + * m4/javacomp.m4 (gt_JAVACOMP): Accept source-version 11 and + target-version 11. + * lib/javaversion.h: Update comments. + * lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND, + source_version_index, get_goodcode_snippet, get_failcode_snippet, + TARGET_VERSION_BOUND, target_version_index, + corresponding_classfile_version): Accept source_version 11 and + target_version 11. + * lib/javacomp.h: Update comments accordingly. + 2018-09-23 Bruno Haible <br...@clisp.org> vasnprintf: Fix heap memory overrun bug. diff --git a/lib/javacomp.c b/lib/javacomp.c index d710085..1c08ec6 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -106,7 +106,8 @@ default_target_version (void) || (java_version_cache[0] == '9' && java_version_cache[1] == '\0') || (java_version_cache[0] == '1' - && java_version_cache[1] == '0' + && (java_version_cache[1] >= '0' + && java_version_cache[1] <= '1') && java_version_cache[2] == '\0'))) java_version_cache = "1.1"; } @@ -116,7 +117,7 @@ default_target_version (void) /* ======================= Source version dependent ======================= */ /* Convert a source version to an index. */ -#define SOURCE_VERSION_BOUND 7 /* exclusive upper bound */ +#define SOURCE_VERSION_BOUND 8 /* exclusive upper bound */ static unsigned int source_version_index (const char *source_version) { @@ -131,9 +132,10 @@ source_version_index (const char *source_version) } else if (source_version[0] == '9' && source_version[1] == '\0') return 5; - else if (source_version[0] == '1' && source_version[1] == '0' + else if (source_version[0] == '1' + && (source_version[1] >= '0' && source_version[1] <= '1') && source_version[2] == '\0') - return 6; + return source_version[1] - '0' + 6; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return 0; } @@ -156,6 +158,8 @@ get_goodcode_snippet (const char *source_version) return "interface conftest { private void foo () {} }\n"; if (strcmp (source_version, "10") == 0) return "class conftest { public void m() { var i = new Integer(0); } }\n"; + if (strcmp (source_version, "11") == 0) + return "class conftest { Readable r = (var b) -> 0; }\n"; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return NULL; } @@ -179,6 +183,8 @@ get_failcode_snippet (const char *source_version) if (strcmp (source_version, "9") == 0) return "class conftestfail { public void m() { var i = new Integer(0); } }\n"; if (strcmp (source_version, "10") == 0) + return "class conftestfail { Readable r = (var b) -> 0; }\n"; + if (strcmp (source_version, "11") == 0) return NULL; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return NULL; @@ -187,7 +193,7 @@ get_failcode_snippet (const char *source_version) /* ======================= Target version dependent ======================= */ /* Convert a target version to an index. */ -#define TARGET_VERSION_BOUND 10 /* exclusive upper bound */ +#define TARGET_VERSION_BOUND 11 /* exclusive upper bound */ static unsigned int target_version_index (const char *target_version) { @@ -197,9 +203,10 @@ target_version_index (const char *target_version) return target_version[2] - '1'; else if (target_version[0] == '9' && target_version[1] == '\0') return 8; - else if (target_version[0] == '1' && target_version[1] == '0' + else if (target_version[0] == '1' + && (target_version[1] >= '0' && target_version[1] <= '1') && target_version[2] == '\0') - return 9; + return target_version[1] - '0' + 9; error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class")); return 0; } @@ -229,6 +236,8 @@ corresponding_classfile_version (const char *target_version) return 53; if (strcmp (target_version, "10") == 0) return 54; + if (strcmp (target_version, "11") == 0) + return 55; error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class")); return 0; } diff --git a/lib/javacomp.h b/lib/javacomp.h index 7f33d98..662e949 100644 --- a/lib/javacomp.h +++ b/lib/javacomp.h @@ -33,6 +33,7 @@ 1.8 lambdas 9 private interface methods 10 type inference for local variables + 11 'var' in parameters of lambda expressions target_version can be: classfile version: 1.1 45.3 1.2 46.0 @@ -44,6 +45,7 @@ 1.8 52.0 9 53.0 10 54.0 + 11 55.0 target_version can also be given as NULL. In this case, the required target_version is determined from the found JVM (see javaversion.h). Specifying target_version is useful when building a library (.jar) that is @@ -56,7 +58,8 @@ - target_version < 1.7 with source_version >= 1.7, or - target_version < 1.8 with source_version >= 1.8, or - target_version < 9 with source_version >= 9, or - - target_version < 10 with source_version >= 10, + - target_version < 10 with source_version >= 10, or + - target_version < 11 with source_version >= 11, because even Sun's/Oracle's javac doesn't support these combinations. It is redundant to ask for a target_version > source_version, since the smaller target_version = source_version will also always work and newer JVMs diff --git a/lib/javaversion.h b/lib/javaversion.h index e7ab435..9c36f52 100644 --- a/lib/javaversion.h +++ b/lib/javaversion.h @@ -26,7 +26,7 @@ extern "C" { /* Return information about the Java version used by execute_java_class(). This is the value of System.getProperty("java.specification.version"). - Some possible values are: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9, 10. + Some possible values are: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9, 10, 11. Return NULL if the Java version cannot be determined. */ extern char * javaexec_version (void); diff --git a/m4/javacomp.m4 b/m4/javacomp.m4 index bee333e..97b7a17 100644 --- a/m4/javacomp.m4 +++ b/m4/javacomp.m4 @@ -1,4 +1,4 @@ -# javacomp.m4 serial 16 +# javacomp.m4 serial 17 dnl Copyright (C) 2001-2003, 2006-2007, 2009-2018 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -20,6 +20,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.8 lambdas # 9 private interface methods # 10 type inference for local variables +# 11 'var' in parameters of lambda expressions # Instead of source-version 1.6, use 1.5, since Java 6 did not introduce any # language changes. See # https://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html @@ -35,6 +36,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.8 52.0 # 9 53.0 # 10 54.0 +# 11 55.0 # The classfile version of a .class file can be determined through the "file" # command. More portably, the classfile major version can be determined through # "od -A n -t d1 -j 7 -N 1 classfile". @@ -51,6 +53,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.8 JDK/JRE 8 # 9 JDK/JRE 9 # 10 JDK/JRE 10 +# 11 JDK/JRE 11 # Note: gij >= 3.3 can in some cases handle classes compiled with -target 1.4, # and gij >= 4.1 can in some cases partially handle classes compiled with # -target 1.5, but I have no idea how complete this support is. Similarly, @@ -68,7 +71,8 @@ dnl with or without modifications, as long as this notice is preserved. # - target_version < 1.7 with source_version >= 1.7, or # - target_version < 1.8 with source_version >= 1.8, or # - target_version < 9 with source_version >= 9, or -# - target_version < 10 with source_version >= 10, +# - target_version < 10 with source_version >= 10, or +# - target_version < 11 with source_version >= 11, # because even Sun's/Oracle's javac doesn't support these combinations. # # It is redundant to ask for a target-version > source-version, since the @@ -122,7 +126,7 @@ changequote([,])dnl CLASSPATH=.${CLASSPATH:+$CLASSPATH_SEPARATOR$CLASSPATH} $CONF_JAVA conftestver 2>&AS_MESSAGE_LOG_FD }` case "$target_version" in - 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9 | 10) ;; + 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9 | 10 | 11) ;; null) dnl JDK 1.1.X returns null. target_version=1.1 ;; @@ -148,6 +152,8 @@ changequote([,])dnl 9) goodcode='interface conftest { private void foo () {} }' failcode='class conftestfail { public void m() { var i = new Integer(0); } }' ;; 10) goodcode='class conftest { public void m() { var i = new Integer(0); } }' + failcode='class conftestfail { Readable r = (var b) -> 0; }' ;; + 11) goodcode='class conftest { Readable r = (var b) -> 0; }' failcode='class conftestfail syntax error' ;; *) AC_MSG_ERROR([invalid source-version argument to gt_@&t@JAVACOMP: $source_version]) ;; esac @@ -162,6 +168,7 @@ changequote([,])dnl 1.8) cfversion=52 ;; 9) cfversion=53 ;; 10) cfversion=54 ;; + 11) cfversion=55 ;; *) AC_MSG_ERROR([invalid target-version argument to gt_@&t@JAVACOMP: $target_version]) ;; esac # Function to output the classfile version of a file (8th byte) in decimal. @@ -245,6 +252,14 @@ changequote([,])dnl dnl -target 1.8 only possible with -source 1.6/1.7/1.8 dnl -target 9 only possible with -source 1.6/1.7/1.8/9 dnl + dnl javac 11: -target 1.6 1.7 1.8 9 10 11 default: 11 + dnl -source 1.6 1.7 1.8 9 10 11 default: 11 + dnl -target 1.6 only possible with -source 1.6 + dnl -target 1.7 only possible with -source 1.6/1.7 + dnl -target 1.8 only possible with -source 1.6/1.7/1.8 + dnl -target 9 only possible with -source 1.6/1.7/1.8/9 + dnl -target 10 only possible with -source 1.6/1.7/1.8/9/10 + dnl dnl The support of jikes for target-version and source-version: dnl dnl jikes 1.14 does not have a way to specify the target-version. It -- 2.7.4
>From 0782fa4dc036a709d5501a8712c5331489c28be9 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 26 Sep 2018 22:14:07 +0200 Subject: [PATCH 2/2] javacomp-script, javacomp: Add preliminary support for Java 12..17. * m4/javacomp.m4 (gt_JAVACOMP): Treat Java versions 12..17 like 11. * lib/javacomp.c (default_target_version): Likewise. --- ChangeLog | 6 ++++++ lib/javacomp.c | 17 ++++++++++++++--- m4/javacomp.m4 | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3dad3ae..45d85f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2018-09-26 Bruno Haible <br...@clisp.org> + javacomp-script, javacomp: Add preliminary support for Java 12..17. + * m4/javacomp.m4 (gt_JAVACOMP): Treat Java versions 12..17 like 11. + * lib/javacomp.c (default_target_version): Likewise. + +2018-09-26 Bruno Haible <br...@clisp.org> + javacomp-script, javacomp: Add support for Java 11. * m4/javacomp.m4 (gt_JAVACOMP): Accept source-version 11 and target-version 11. diff --git a/lib/javacomp.c b/lib/javacomp.c index 1c08ec6..9d5b249 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -98,8 +98,9 @@ default_target_version (void) { /* Determine the version from the found JVM. */ java_version_cache = javaexec_version (); - if (java_version_cache == NULL - || !((java_version_cache[0] == '1' + if (java_version_cache == NULL) + java_version_cache = "1.1"; + else if ((java_version_cache[0] == '1' && java_version_cache[1] == '.' && java_version_cache[2] >= '1' && java_version_cache[2] <= '8' && java_version_cache[3] == '\0') @@ -108,7 +109,17 @@ default_target_version (void) || (java_version_cache[0] == '1' && (java_version_cache[1] >= '0' && java_version_cache[1] <= '1') - && java_version_cache[2] == '\0'))) + && java_version_cache[2] == '\0')) + /* It's one of the valid target version values. */ + ; + else if (java_version_cache[0] == '1' + && (java_version_cache[1] >= '2' + && java_version_cache[1] <= '7') + && java_version_cache[2] == '\0') + /* Assume that these (not yet released) Java versions will behave + like the preceding ones. */ + java_version_cache = "11"; + else java_version_cache = "1.1"; } return java_version_cache; diff --git a/m4/javacomp.m4 b/m4/javacomp.m4 index 97b7a17..1d0cf25 100644 --- a/m4/javacomp.m4 +++ b/m4/javacomp.m4 @@ -127,6 +127,10 @@ changequote([,])dnl }` case "$target_version" in 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9 | 10 | 11) ;; + 12 | 13 | 14 | 15 | 16 | 17) + dnl Assume that these (not yet released) Java versions will behave + dnl like the preceding ones. + target_version=11 ;; null) dnl JDK 1.1.X returns null. target_version=1.1 ;; -- 2.7.4