Christopher wrote:
So, I actually think that building with the *latest* JDK that we
ship,
and using the `--release` flag during compilation is actually safer
than building against the lowest that we support, because it is most
likely to strictly enforce correct byte code generation for the target
JRE.
The problem is, without ALSO installing the JDK for the targeted version AND
explicitly pointing -bootclasspath to that JDK, this does NOT catch code
trying to use class library features (as opposed to language or bytecode
features) from the newer JDK, and worse, in rare occasions, even if the
source code is in principle compatible with the targeted older Java, when
compiled with a newer compiler and older target release, it will fail to
actually run (!) with the latter (because the compiler picks up a subclass
override of a method added in the newer Java instead of the baseclass method
that was always available and, for performance reasons, tries calling the
override explicitly rather than going through the virtual method lookup).
One example of that latter issue is NetBeans, where versions 12.5 and 12.6
were supposed to be compatible with Java 8, but some upstream-published
binaries of 12.5 and all of 12.6 do not actually work properly on it because
they were built with Java 11 in "-release 8" mode: some editor features fail
with runtime exceptions. See
https://issues.apache.org/jira/browse/NETBEANS-6349 for details. (They
"fixed" it by just requiring Java 11 in NetBeans 13 and newer. No fixed 12.x
release was ever issued.)
So I am AGAINST systematically using "-release" without
"-bootclasspath",
even though that works in most cases and is often successfully used in
production (me and my employer use it, too, but on projects we control where
we will fix the source code or add a workaround to it if any issues come up
from that, not systematically on repackaging third-party projects). The
compiler even warns about the missing "-bootclasspath". And the potential to
cause subtle misbehavior that is a pain to debug is just too high,
especially if we have the actual older JDK available and could just
BuildRequire the correct version.
Kevin Kofler