A build of GNU Bison with Gnulib HEAD on macOS 13 fails:
After configure has found
checking for Java compiler... javac -Xlint:-options -source 1.7 -target 1.7
"make check" fails like this:
...
GEN examples/java/calc/Calc.java
GEN examples/java/calc/Calc.class
error: Source option 7 is no longer supported. Use 8 or later.
error: Target option 7 is no longer supported. Use 8 or later.
make[3]: *** [examples/java/calc/Calc.class] Error 2
Recent JDKs cannot compile source code meant for Java 7 and older any more.
This is because Java 7 is unsupported for more than two years already:
https://en.wikipedia.org/wiki/Java_version_history#Release_table
One possible fix is to change bison/configure.ac, replacing
gt_JAVACOMP([1.7], [1.7])
with
gt_JAVACOMP([1.8], [1.8])
But Bison is not the only package that uses gt_JAVACOMP. In GNU gettext,
I made this change already a year ago. But it's tiresome to make the same
change in all packages; it's better to make it centrally in Gnulib.
Done through the following patch:
2025-07-13 Bruno Haible <[email protected]>
javacomp-script, javacomp: Remove support for javac versions < 1.8.
* m4/javacomp.m4 (gt_JAVACOMP): State that the minimum source_version
and the minimum target_version are 1.8. Map smaller values to 1.8.
Complain if the java version is < 1.8. Use 1.8 as default, instead of
1.6.
* lib/javacomp.h (compile_java_class): State that the minimum
source_version and the minimum target_version are 1.8.
* lib/javacomp.c (default_target_version): Complain if the java version
is < 1.8. Use 1.8 as default, instead of 1.6.
(SOURCE_VERSION_BOUND, source_version_index): Adjust to the new minimum
source_version = 1.8.
(TARGET_VERSION_BOUND, target_version_index): Adjust to the new minimum
target_version = 1.8.
(get_compiler_version): Update comment.
(is_envjavac_usable, is_javac_usable): Update.
(compile_java_class): Map source_version < 1.8 to 1.8. Map
target_version < 1.8 to 1.8.
diff --git a/lib/javacomp.c b/lib/javacomp.c
index 33ec8eb63e..936cf79810 100644
--- a/lib/javacomp.c
+++ b/lib/javacomp.c
@@ -94,18 +94,18 @@ default_target_version (void)
/* Determine the version from the found JVM. */
java_version_cache = javaexec_version ();
if (java_version_cache == NULL)
- java_version_cache = "1.6";
+ java_version_cache = "1.8";
else if (java_version_cache[0] == '1'
&& java_version_cache[1] == '.'
- && java_version_cache[2] >= '1' && java_version_cache[2] <= '5'
+ && java_version_cache[2] >= '1' && java_version_cache[2] <= '7'
&& java_version_cache[3] == '\0')
{
error (0, 0, _("The java program is too old. Cannot compile Java
code for this old version any more."));
- java_version_cache = "1.6";
+ java_version_cache = "1.8";
}
else if ((java_version_cache[0] == '1'
&& java_version_cache[1] == '.'
- && java_version_cache[2] >= '6' && java_version_cache[2] <= '8'
+ && java_version_cache[2] == '8'
&& java_version_cache[3] == '\0')
|| (java_version_cache[0] == '9'
&& java_version_cache[1] == '\0')
@@ -120,7 +120,7 @@ default_target_version (void)
determined from the JVM, we do that. */
;
else
- java_version_cache = "1.6";
+ java_version_cache = "1.8";
}
return java_version_cache;
}
@@ -128,22 +128,21 @@ default_target_version (void)
/* ======================= Source version dependent ======================= */
/* Convert a source version to an index. */
-#define SOURCE_VERSION_BOUND 94 /* exclusive upper bound */
+#define SOURCE_VERSION_BOUND 92 /* exclusive upper bound */
static unsigned int
source_version_index (const char *source_version)
{
if (source_version[0] == '1' && source_version[1] == '.')
{
- if ((source_version[2] >= '6' && source_version[2] <= '8')
- && source_version[3] == '\0')
- return source_version[2] - '6';
+ if (source_version[2] == '8' && source_version[3] == '\0')
+ return 0;
}
else if (source_version[0] == '9' && source_version[1] == '\0')
- return 3;
+ return 1;
else if ((source_version[0] >= '1' && source_version[0] <= '9')
&& (source_version[1] >= '0' && source_version[1] <= '9')
&& source_version[2] == '\0')
- return (source_version[0] - '1') * 10 + source_version[1] - '0' + 4;
+ return (source_version[0] - '1') * 10 + source_version[1] - '0' + 2;
error (EXIT_FAILURE, 0, _("invalid source_version argument to
compile_java_class"));
return 0;
}
@@ -151,20 +150,19 @@ source_version_index (const char *source_version)
/* ======================= Target version dependent ======================= */
/* Convert a target version to an index. */
-#define TARGET_VERSION_BOUND 94 /* exclusive upper bound */
+#define TARGET_VERSION_BOUND 92 /* exclusive upper bound */
static unsigned int
target_version_index (const char *target_version)
{
if (target_version[0] == '1' && target_version[1] == '.'
- && (target_version[2] >= '6' && target_version[2] <= '8')
- && target_version[3] == '\0')
- return target_version[2] - '6';
+ && target_version[2] == '8' && target_version[3] == '\0')
+ return 0;
else if (target_version[0] == '9' && target_version[1] == '\0')
- return 3;
+ return 1;
else if ((target_version[0] >= '1' && target_version[0] <= '9')
&& (target_version[1] >= '0' && target_version[1] <= '9')
&& target_version[2] == '\0')
- return (target_version[0] - '1') * 10 + target_version[1] - '0' + 4;
+ return (target_version[0] - '1') * 10 + target_version[1] - '0' + 2;
error (EXIT_FAILURE, 0, _("invalid target_version argument to
compile_java_class"));
return 0;
}
@@ -414,7 +412,7 @@ get_compiler_version (const char *progname,
version_end++;
*version_end = '\0';
- /* Map 1.6.0_85 to 6, 1.8.0_151 to 8. Map 9.0.4 to 9, 10.0.2 to 10, etc. */
+ /* Map 1.8.0_151 to 8. Map 9.0.4 to 9, 10.0.2 to 10, etc. */
if (version_start[0] == '1' && version_start[1] == '.')
version_start += 2;
version_end = strchr (version_start, '.');
@@ -525,8 +523,8 @@ is_envjavac_usable (const char *javac,
{
/* Canonicalize source_version and target_version, for easier
arithmetic. */
- int try_source_version = 6 + source_version_index (source_version);
- int try_target_version = 6 + target_version_index (target_version);
+ int try_source_version = 8 + source_version_index (source_version);
+ int try_target_version = 8 + target_version_index (target_version);
/* Sanity check. */
if (try_source_version <= try_target_version)
{
@@ -801,8 +799,8 @@ is_javac_usable (const char *source_version, const char
*target_version,
{
/* Canonicalize source_version and target_version, for easier
arithmetic. */
- int try_source_version = 6 + source_version_index (source_version);
- int try_target_version = 6 + target_version_index (target_version);
+ int try_source_version = 8 + source_version_index (source_version);
+ int try_target_version = 8 + target_version_index (target_version);
/* Sanity check. */
if (try_source_version <= try_target_version)
{
@@ -1013,18 +1011,18 @@ compile_java_class (const char * const *java_sources,
bool err = false;
char *old_JAVA_HOME;
- /* Map source_version 1.1 ... 1.5 to 1.6. */
+ /* Map source_version 1.1 ... 1.7 to 1.8. */
if (source_version[0] == '1' && source_version[1] == '.'
- && (source_version[2] >= '1' && source_version[2] <= '5')
+ && (source_version[2] >= '1' && source_version[2] <= '7')
&& source_version[3] == '\0')
- source_version = "1.6";
+ source_version = "1.8";
- /* Map target_version 1.1 ... 1.5 to 1.6. */
+ /* Map target_version 1.1 ... 1.7 to 1.8. */
if (target_version != NULL
&& target_version[0] == '1' && target_version[1] == '.'
- && (target_version[2] >= '1' && target_version[2] <= '5')
+ && (target_version[2] >= '1' && target_version[2] <= '7')
&& target_version[3] == '\0')
- target_version = "1.6";
+ target_version = "1.8";
{
const char *javac = getenv ("JAVAC");
diff --git a/lib/javacomp.h b/lib/javacomp.h
index b93893bed2..acb842ca17 100644
--- a/lib/javacomp.h
+++ b/lib/javacomp.h
@@ -28,28 +28,27 @@ extern "C" {
classpaths is a list of pathnames to be prepended to the CLASSPATH.
source_version can be: support for
- 1.6 assert keyword (1.4), generic classes and methods
(1.5)
- 1.7 switch(string)
1.8 lambdas
9 private interface methods
10 type inference for local variables
11 'var' in parameters of lambda expressions
...
- If source-version 1.3 or 1.4 or 1.5 is requested, it gets mapped to 1.6, for
- backward compatibility. (Currently the minimum Java and javac version we
need
- to support is Java 1.6, since that's the default Java version on Solaris
10.)
+ If source-version 1.3 or 1.4 or 1.5 or 1.6 or 1.7 is requested, it gets
+ mapped to 1.8, for backward compatibility. (Currently the minimum Java and
+ javac version we need to support is Java 1.8, since older versions are
+ out-of-support, see
+ <https://en.wikipedia.org/wiki/Java_version_history#Release_table>.)
target_version can be: classfile version:
- 1.6 50.0
- 1.7 51.0
1.8 52.0
9 53.0
10 54.0
11 55.0
... ...
- If a target-version below 1.6 is requested, it gets mapped to 1.6, for
- backward compatibility. (Currently the minimum Java and javac version we
need
- to support is Java 1.6, since that's the default Java version on Solaris
10.)
+ If a target-version below 1.8 is requested, it gets mapped to 1.8, for
+ backward compatibility. (Currently the minimum Java and javac version we
+ need to support is Java 1.8, since older versions are out-of-support, see
+ <https://en.wikipedia.org/wiki/Java_version_history#Release_table>.)
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
diff --git a/m4/javacomp.m4 b/m4/javacomp.m4
index 2e96c56dcd..8148b45306 100644
--- a/m4/javacomp.m4
+++ b/m4/javacomp.m4
@@ -1,5 +1,5 @@
# javacomp.m4
-# serial 26
+# serial 27
dnl Copyright (C) 2001-2003, 2006-2007, 2009-2025 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
@@ -14,21 +14,19 @@
# target-version format.
#
# source-version can be: support for
-# 1.6 assert keyword (1.4), generic classes and methods
(1.5)
-# 1.7 switch(string)
# 1.8 lambdas
# 9 private interface methods
# 10 type inference for local variables
# 11 'var' in parameters of lambda expressions
# ...
# (For reference, see <https://en.wikipedia.org/wiki/Java_version_history>.)
-# If source-version 1.3 or 1.4 or 1.5 is requested, it gets mapped to 1.6, for
-# backward compatibility. (Currently the minimum Java and javac version we need
-# to support is Java 1.6, since that's the default Java version on Solaris 10.)
+# If source-version 1.3 or 1.4 or 1.5 or 1.6 or 1.7 is requested, it gets
mapped
+# to 1.8, for backward compatibility. (Currently the minimum Java and javac
+# version we need to support is Java 1.8, since older versions are
+# out-of-support, see
+# <https://en.wikipedia.org/wiki/Java_version_history#Release_table>.)
#
# target-version can be: classfile version:
-# 1.6 50.0
-# 1.7 51.0
# 1.8 52.0
# 9 53.0
# 10 54.0
@@ -37,15 +35,14 @@
# 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".
-# If a target-version below 1.6 is requested, it gets mapped to 1.6, for
+# If a target-version below 1.8 is requested, it gets mapped to 1.8, for
# backward compatibility. (Currently the minimum Java and javac version we need
-# to support is Java 1.6, since that's the default Java version on Solaris 10.)
+# to support is Java 1.8, since older versions are out-of-support, see
+# <https://en.wikipedia.org/wiki/Java_version_history#Release_table>.)
#
# target-version can also be omitted. In this case, the required target-version
# is determined from the found JVM (see macro gt_JAVAEXEC):
# target-version for JVM
-# 1.6 JDK/JRE 6
-# 1.7 JDK/JRE 7
# 1.8 JDK/JRE 8
# 9 JDK/JRE 9
# 10 JDK/JRE 10
@@ -85,7 +82,7 @@ AC_DEFUN([gt_JAVACOMP]
AC_MSG_ERROR([missing source-version argument to gt_@&t@JAVACOMP])
}
case "$source_version" in
- 1.1 | 1.2 | 1.3 | 1.4 | 1.5) source_version='1.6' ;;
+ 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7) source_version='1.8' ;;
esac
m4_if([$2], [],
[if test -n "$HAVE_JAVAEXEC"; then
@@ -123,11 +120,11 @@ AC_DEFUN([gt_JAVACOMP]
java_exec_version=1.1 ;;
esac
case "$java_exec_version" in
- 1.1 | 1.2 | 1.3 | 1.4 | 1.5)
+ 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7)
AC_MSG_WARN([$CONF_JAVA is too old, cannot compile Java code for
this old version any more])
- target_version=1.6 ;;
+ target_version=1.8 ;;
changequote(,)dnl
- 1.6 | 1.7 | 1.8 | 9 | [1-9][0-9])
+ 1.8 | 9 | [1-9][0-9])
changequote([,])dnl
dnl Here we could choose any target_version between $source_version
dnl and the $java_exec_version. (If it is too small, it will be
@@ -135,26 +132,26 @@ AC_DEFUN([gt_JAVACOMP]
dnl it is determined from the JVM, we do that:
target_version="$java_exec_version" ;;
*) AC_MSG_WARN([unknown target-version $target_version, please update
gt_@&t@JAVACOMP macro])
- target_version=1.6 ;;
+ target_version=1.8 ;;
esac
else
- target_version="1.6"
+ target_version="1.8"
fi
],
[target_version=$2
case "$target_version" in
- 1.1 | 1.2 | 1.3 | 1.4 | 1.5) target_version='1.6' ;;
+ 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7) target_version='1.8' ;;
esac
])
case "$source_version" in
changequote(,)dnl
- 1.6 | 1.7 | 1.8 | 9 | [1-9][0-9]) ;;
+ 1.8 | 9 | [1-9][0-9]) ;;
changequote([,])dnl
*) AC_MSG_ERROR([invalid source-version argument to gt_@&t@JAVACOMP:
$source_version]) ;;
esac
case "$target_version" in
changequote(,)dnl
- 1.6 | 1.7 | 1.8 | 9 | [1-9][0-9]) ;;
+ 1.8 | 9 | [1-9][0-9]) ;;
changequote([,])dnl
*) AC_MSG_ERROR([invalid target-version argument to gt_@&t@JAVACOMP:
$target_version]) ;;
esac
@@ -177,19 +174,6 @@ AC_DEFUN([gt_JAVACOMP]
dnl
dnl The support of Sun/Oracle javac for target-version and source-version:
dnl
- dnl javac 1.6: -target 1.1 1.2 1.3 1.4 1.5 1.6 default: 1.6
- dnl -source 1.3 1.4 1.5 1.6 default: 1.5
- dnl -target 1.1/1.2/1.3 only possible with -source 1.3
- dnl -target 1.4 only possible with -source 1.3/1.4
- dnl -target 1.5 only possible with -source 1.3/1.4/1.5 or no
-source
- dnl
- dnl javac 1.7: -target 1.1 1.2 1.3 1.4 1.5 1.6 1.7 default: 1.7
- dnl -source 1.3 1.4 1.5 1.6 1.7 default: 1.7
- dnl -target 1.1/1.2/1.3 only possible with -source 1.3
- dnl -target 1.4 only possible with -source 1.3/1.4
- dnl -target 1.5 only possible with -source 1.3/1.4/1.5
- dnl -target 1.6 only possible with -source 1.3/1.4/1.5/1.6
- dnl
dnl javac 1.8: -target 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 default: 1.8
dnl -source 1.3 1.4 1.5 1.6 1.7 1.8 default: 1.8
dnl -target 1.1/1.2/1.3 only possible with -source 1.3
@@ -217,8 +201,6 @@ AC_DEFUN([gt_JAVACOMP]
dnl javac classfile valid -source and obsolete -source
dnl version default version -target values and -target values
dnl ------- --------------- ----------------- ------------------
- dnl 1.6 50.0 1.2 .. 1.6
- dnl 1.7 51.0 1.2 .. 1.7
dnl 1.8 52.0 1.3 .. 1.8 1.3 .. 1.5
dnl 9 53.0 1.6 .. 9 1.6
dnl 10 54.0 1.6 .. 10 1.6
@@ -318,7 +300,7 @@ AC_DEFUN([gt_JAVACOMP]
compiler_version=`echo "$compiler_version" | sed -e
's/^[^0-9]*\([0-9][0-9.]*\).*/\1/'`
changequote([,])dnl
case "$compiler_version" in
- 1.*) dnl Map 1.6.0_85 to 6, 1.8.0_151 to 8.
+ 1.*) dnl Map 1.8.0_151 to 8.
compiler_version=`echo "$compiler_version" | sed -e
's/^1\.//' -e 's/\..*//'`
;;
*) dnl Map 9.0.4 to 9, 10.0.2 to 10, etc.
@@ -340,11 +322,11 @@ AC_DEFUN([gt_JAVACOMP]
fi
try_source_version=`expr $try_source_version + 1`
expr $try_source_version '<=' $compiler_version >/dev/null ||
break
- source_option=' -source '`case "$try_source_version" in 6|7|8)
echo 1. ;; esac`"$try_source_version"
+ source_option=' -source '`case "$try_source_version" in 8) echo
1. ;; esac`"$try_source_version"
if expr $try_target_version = $compiler_target_version
>/dev/null; then
target_option=
else
- target_option=' -target '`case "$try_target_version" in 6|7|8)
echo 1. ;; esac`"$try_target_version"
+ target_option=' -target '`case "$try_target_version" in 8)
echo 1. ;; esac`"$try_target_version"
fi
if { echo "$as_me:__oline__:
$JAVAC$nowarn_option$source_option$target_option -d . conftest.java"
>&AS_MESSAGE_LOG_FD
$JAVAC$nowarn_option$source_option$target_option -d .
conftest.java >&AS_MESSAGE_LOG_FD 2>&1
@@ -397,13 +379,13 @@ AC_DEFUN([gt_JAVACOMP]
dnl Also, javac may point to a shell script that already includes a
dnl '-source' option.
dnl Therefore, pass a '-source' option always.
- source_option=' -source '`case "$source_version" in 6|7|8) echo 1.
;; esac`"$source_version"
+ source_option=' -source '`case "$source_version" in 8) echo 1. ;;
esac`"$source_version"
dnl And pass a '-target' option as well, if needed.
dnl (All supported javac versions support both, see the table above.)
if expr $target_version = $compiler_target_version >/dev/null; then
target_option=
else
- target_option=' -target '`case "$target_version" in 6|7|8) echo 1.
;; esac`"$target_version"
+ target_option=' -target '`case "$target_version" in 8) echo 1. ;;
esac`"$target_version"
fi
if { echo "$as_me:__oline__:
javac$nowarn_option$source_option$target_option -d . conftest.java"
>&AS_MESSAGE_LOG_FD
javac$nowarn_option$source_option$target_option -d .
conftest.java >&AS_MESSAGE_LOG_FD 2>&1
@@ -423,7 +405,7 @@ AC_DEFUN([gt_JAVACOMP]
compiler_version=`echo "$compiler_version" | sed -e
's/^[^0-9]*\([0-9][0-9.]*\).*/\1/'`
changequote([,])dnl
case "$compiler_version" in
- 1.*) dnl Map 1.6.0_85 to 6, 1.8.0_151 to 8.
+ 1.*) dnl Map 1.8.0_151 to 8.
compiler_version=`echo "$compiler_version" | sed -e
's/^1\.//' -e 's/\..*//'`
;;
*) dnl Map 9.0.4 to 9, 10.0.2 to 10, etc.
@@ -445,11 +427,11 @@ AC_DEFUN([gt_JAVACOMP]
fi
try_source_version=`expr $try_source_version + 1`
expr $try_source_version '<=' $compiler_version >/dev/null ||
break
- source_option=' -source '`case "$try_source_version" in 6|7|8)
echo 1. ;; esac`"$try_source_version"
+ source_option=' -source '`case "$try_source_version" in 8)
echo 1. ;; esac`"$try_source_version"
if expr $try_target_version = $compiler_target_version
>/dev/null; then
target_option=
else
- target_option=' -target '`case "$try_target_version" in
6|7|8) echo 1. ;; esac`"$try_target_version"
+ target_option=' -target '`case "$try_target_version" in 8)
echo 1. ;; esac`"$try_target_version"
fi
if { echo "$as_me:__oline__:
javac$nowarn_option$source_option$target_option -d . conftest.java"
>&AS_MESSAGE_LOG_FD
javac$nowarn_option$source_option$target_option -d .
conftest.java >&AS_MESSAGE_LOG_FD 2>&1