Please consider the attached debdiff for review.

On why it is important to use --release instead of the usual -source/-target:
any package that is not build with it can run into those
incompatibilities at runtime when run with an older (but targeted)
release. As a lot of libraries are being build with only
-source/-target set any package that depend on those won't run on
older (but targeted) jdk. It can also affect builds in case the
compiled tool is run during build time with the same old targeted jdk
- see bug #895234 where it was impossible to build
libcommons-lang3-java with openjdk-8 because bnd would fail. In fact,
for the affected packages (ie. use of flip()Ljava/nio/ByteBuffer),
since the build works but runtime fails the current scenario is the
same as setting -target 1.9.

This is already happening with the transition from openjdk-8 to 9 and,
although there's no such indication, it could also affect the
transition from 9/10 to 11 if they do similar changes to the JDK.

Another alternative to using --release is fixing the code that uses
the incompatible API, such as was done for gradle [1], but that does
not scale as well and it is reactive since errors are only detected
during runtime.

Regards,
Tiago

References:
[1] 
https://sources.debian.org/src/gradle/3.4.1-7/debian/patches/java8-compatibility.patch

On Fri, Apr 13, 2018 at 12:14 PM, Tiago Stürmer Daitx
<tiago.da...@canonical.com> wrote:
> Source: plexus-compiler
> Version: 2.8.2-5
> Severity: normal
>
> Dear Maintainer,
>
> plexus-compiler currently will default -source and/or -target to 1.7
> whenever the following occours:
> 1) whenever either has not being set
> 2) whenever either has been set to 1.6 or earlier
>
> This patch modifies the detection logic in order to be able to set the
> '--release' flag when (and only when):
> - the '--release' is *not* set
> - AND both -source and -target are being set to a default value
> - AND the running jvm is jdk9 or newer
>
> This prevents errors such as the infamous "Method
> flip()Ljava/nio/ByteBuffer; does not exist in class java.nio.ByteBuffer"
> that is caused by building with openjdk-9 with -source set without
> setting the proper bootclasspath [1,2]. JEP-247 [3] has provided the
> --release to prevent such issues and should be used instead of -source
> whenever the javac being used is jdk9 or higher.
>
>
> I have tested and I can confirm it works fine, but I would like some
> review to make sure it is sane and get opinions on other (better?) ways
> to do this - specially concerning the detection of the jvm being run.
>
> Also, fork and an alternative javac compiler might be set, thus I would
> like to discuss as to what behavior it should default it in that case.
>
> Regards,
> Tiago Daitx
>
> References:
> [1] https://bugs.launchpad.net/ubuntu/+source/gradle/+bug/1760359
> [2] https://github.com/plasma-umass/doppio/issues/497
> [3] http://openjdk.java.net/jeps/247
>
>
> -- System Information:
> Debian Release: buster/sid
>   APT prefers bionic
>   APT policy: (500, 'bionic'), (400, 'bionic-proposed')
> Architecture: amd64 (x86_64)
> Foreign Architectures: i386
>
> Kernel: Linux 4.15.0-13-generic (SMP w/8 CPU cores)
> Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
> LANGUAGE=en_US (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> Init: systemd (via /run/systemd/system)
> LSM: AppArmor: enabled



-- 
Tiago Stürmer Daitx
Software Engineer
tiago.da...@canonical.com

PGP Key: 4096R/F5B213BE (hkp://keyserver.ubuntu.com)
Fingerprint = 45D0 FE5A 8109 1E91 866E  8CA4 1931 8D5E F5B2 13BE
diff -Nru plexus-compiler-2.8.2/debian/changelog plexus-compiler-2.8.2/debian/changelog
--- plexus-compiler-2.8.2/debian/changelog	2017-09-18 10:31:35.000000000 -0300
+++ plexus-compiler-2.8.2/debian/changelog	2018-04-12 11:35:44.000000000 -0300
@@ -1,3 +1,10 @@
+plexus-compiler (2.8.2-6~01) UNRELEASED; urgency=medium
+
+  * Use a default --release instead of defaults -source/-target in order to
+    have the right bootclasspath set as per JEP 247. (Closes: #895619)
+
+ -- Tiago Stürmer Daitx <tiago.da...@ubuntu.com>  Thu, 12 Apr 2018 14:35:44 +0000
+
 plexus-compiler (2.8.2-5) unstable; urgency=medium
 
   * Team upload.
diff -Nru plexus-compiler-2.8.2/debian/patches/auto-adjust-language-level.patch plexus-compiler-2.8.2/debian/patches/auto-adjust-language-level.patch
--- plexus-compiler-2.8.2/debian/patches/auto-adjust-language-level.patch	2017-07-04 03:58:08.000000000 -0300
+++ plexus-compiler-2.8.2/debian/patches/auto-adjust-language-level.patch	2018-04-12 11:35:44.000000000 -0300
@@ -3,40 +3,81 @@
 Forwarded: not-needed
 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
 +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
-@@ -339,12 +339,20 @@
+@@ -339,30 +339,64 @@ public class JavacCompiler
          }
          else
          {
+-            // TODO: this could be much improved
+-            if ( StringUtils.isEmpty( config.getTargetVersion() ) )
++            int classVersion = 0;
++            try
+             {
+-                // Required, or it defaults to the target of your JDK (eg 1.5)
+-                args.add( "-target" );
+-                args.add( "1.1" );
++                classVersion = Float.valueOf( System.getProperty( "java.class.version", "0" ) ).intValue();
+             }
+-            else
++            catch (Exception e)
+             {
+-                args.add( "-target" );
+-                args.add( config.getTargetVersion() );
+             }
+ 
+-            if ( !suppressSource( config ) && StringUtils.isEmpty( config.getSourceVersion() ) )
++            boolean useDefaultSource = true;
++            boolean useDefaultTarget = true;
 +            List<String> unsupportedLanguageLevels = java.util.Arrays.asList(new String[]{"1.1", "1.2", "1.3", "1.4", "1.5", "5"});
 +
-             // TODO: this could be much improved
-             if ( StringUtils.isEmpty( config.getTargetVersion() ) )
++            // TODO: this could be much improved
++            if ( !StringUtils.isEmpty( config.getTargetVersion() ) && !unsupportedLanguageLevels.contains( config.getTargetVersion() ) )
              {
-                 // Required, or it defaults to the target of your JDK (eg 1.5)
-                 args.add( "-target" );
--                args.add( "1.1" );
-+                args.add( "1.7" );
-+            }
-+            else if ( unsupportedLanguageLevels.contains( config.getTargetVersion() ) )
-+            {
-+                System.err.println( "Use of target " + config.getTargetVersion() + " is no longer supported, switching to 1.7" );
+-                // If omitted, later JDKs complain about a 1.1 target
+-                args.add( "-source" );
+-                args.add( "1.3" );
++                if ( classVersion >= 53 )
++                {
++                    System.err.println( "Use of maven-compiler-plugin's 'target' option is no longer recommended, consider using 'release' instead" );
++                }
++                useDefaultTarget = false;
 +                args.add( "-target" );
-+                args.add( "1.7" );
++                args.add( config.getTargetVersion() );
++
              }
-             else
-             {
-@@ -356,7 +364,13 @@
+-            else if ( !suppressSource( config ) )
++
++            if ( !suppressSource( config ) && !StringUtils.isEmpty( config.getSourceVersion() ) && !unsupportedLanguageLevels.contains( config.getSourceVersion() ) )
              {
-                 // If omitted, later JDKs complain about a 1.1 target
++                if ( classVersion >= 53 )
++                {
++                    System.err.println( "Use of maven-compiler-plugin's 'source' option is no longer recommended, consider using 'release' instead" );
++                }
++                useDefaultSource = false;
                  args.add( "-source" );
--                args.add( "1.3" );
-+                args.add( "1.7" );
+                 args.add( config.getSourceVersion() );
+             }            
++
++            if ( useDefaultTarget && useDefaultSource && classVersion >= 53 )
++            {
++                args.add( "--release" );
++                args.add( "7" );
 +            }
-+            else if ( !suppressSource( config ) && unsupportedLanguageLevels.contains( config.getSourceVersion() ) )
++	    else
 +            {
-+                 System.err.println( "Use of source " + config.getSourceVersion() + " is no longer supported, switching to 1.7" );
-+                args.add( "-source" );
-+                args.add( "1.7" );
-             }
-             else if ( !suppressSource( config ) )
-             {
++                if ( useDefaultTarget )
++                {
++                    System.err.println( "Use of target " + config.getTargetVersion() + " is no longer supported, switching to 1.7" );
++                    args.add( "-target" );
++                    args.add( "1.7" );
++                }
++                if ( useDefaultSource )
++                {
++                    System.err.println( "Use of source " + config.getSourceVersion() + " is no longer supported, switching to 1.7" );
++                    args.add( "-source" );
++                    args.add( "1.7" );
++                }
++                // Required, or it defaults to the target of your JDK (eg 1.5)
++            }
+         }
+ 
+ 
__
This is the maintainer address of Debian's Java team
<http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-maintainers>. 
Please use
debian-j...@lists.debian.org for discussions and questions.

Reply via email to