Bug 62952 - AntClassLoader is not multi-release JAR aware
Summary: AntClassLoader is not multi-release JAR aware
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.10.5
Hardware: PC Linux
: P2 major (vote)
Target Milestone: 1.10.6
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-26 08:52 UTC by Javier Armendariz
Modified: 2019-01-30 11:15 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Javier Armendariz 2018-11-26 08:52:58 UTC
In the following repository I created an scenario to easily reproduce this:

https://github.com/katanagari7c1/ant-mrjar-support-test

When running the ant script in Java 11, a multi-release JAR file is created and used by an ant Task which prints a message depending on the class file used. In this case the Java 8 class is used ignoring the Java 9+ implementation.
Comment 1 Jaikiran Pai 2018-12-05 11:38:32 UTC
Hello Javier,

It's true that AntClassLoader currently out of the box doesn't support multi-release jar files. The java.util.jar.JarFile documentation[1] has an interesting and useful information which states:

<quote>
Implementation Note:
    If the API can not be used to configure a JarFile (e.g. to override the configuration of a compiled application or library), two System properties are available.

        jdk.util.jar.version can be assigned a value that is the String representation of a non-negative integer <= Runtime.version().major(). The value is used to set the effective runtime version to something other than the default value obtained by evaluating Runtime.version().major(). The effective runtime version is the version that the JarFile(File, boolean, int, Runtime.Version) constructor uses when the value of the last argument is JarFile.runtimeVersion().
        jdk.util.jar.enableMultiRelease can be assigned one of the three String values true, false, or force. The value true, the default value, enables multi-release jar file processing. The value false disables multi-release jar processing, ignoring the "Multi-Release" manifest attribute, and the versioned directories in a multi-release jar file if they exist. Furthermore, the method isMultiRelease() returns false. The value force causes the JarFile to be initialized to runtime versioning after construction. It effectively does the same as this code: (new JarFile(File, boolean, int, JarFile.runtimeVersion()).



</quote>


So I set up the 'jdk.util.jar.enableMultiRelease' system property to 'force' through ANT_OPTS as follows:

export ANT_OPTS="-Djdk.util.jar.enableMultiRelease=force"

and ran your example:

ant -f ant-test.xml

on a Java 9 setup and it worked fine and used the Java 9 version of the task. Here's the snippet from the output:

run.task:
 [testTask] Executing Java9+ Task. MRJAR is supported!
     [echo] ========================================
     [echo] Now using the same jar in a jvm process
     [echo] ========================================
     [java] Executing Java9+ Task. MRJAR is supported!



Having said that, we can certainly make AntClassLoader support multi-release jar file out of the box and I'll go ahead and commit a change for that so it's available in the next release.

[1] https://docs.oracle.com/javase/9/docs/api/java/util/jar/JarFile.html
Comment 2 Jaikiran Pai 2018-12-05 13:01:31 UTC
This is now fixed in upstream master branch and should be available in next release - AntClassLoader now recognizes the runtime environment version and does the necessary work to support multi-release jar files that it uses to load resources at runtime.
Comment 3 Stefan Huehner 2018-12-13 15:09:05 UTC
(In reply to Jaikiran Pai from comment #2)
> This is now fixed in upstream master branch and should be available in next
> release - AntClassLoader now recognizes the runtime environment version and
> does the necessary work to support multi-release jar files that it uses to
> load resources at runtime.

Hello,
coworker of the reporter here.

Thanks for getting that fixed so fast :)

As we are talking to Ubuntu distro for a potential backport to their stable releases...

Do you have any rough ETA for 1.10.6 ant to be released?
Comment 4 Jaikiran Pai 2018-12-14 03:39:23 UTC
>> As we are talking to Ubuntu distro for a potential backport to their stable releases...

>> Do you have any rough ETA for 1.10.6 ant to be released?

We currently don't have a specific date in mind. There's one PR (related to jmod and jlink task) that's open that I think is a good candidate to go in, for this release. Other than that, I don't think there's anything pending. However, we need to see if anyone else in the dev team has anything that they want to be part of this release and also see if one of us can drive the release.

What is the timelines for the Ubuntu distro upgrade that's being planned?
Comment 5 Jaikiran Pai 2018-12-14 03:40:53 UTC
By the way, in case your team is interested in trying out this (or other upcoming changes), then you can give our nightly build a quick try https://builds.apache.org/view/A/view/Ant/job/Ant_Nightly/lastSuccessfulBuild/artifact/distribution/ and make sure things work fine.
Comment 6 Stefan Huehner 2019-01-21 14:04:53 UTC
(In reply to Jaikiran Pai from comment #4)
> >> As we are talking to Ubuntu distro for a potential backport to their stable releases...
> 
> >> Do you have any rough ETA for 1.10.6 ant to be released?
> 
> We currently don't have a specific date in mind. There's one PR (related to
> jmod and jlink task) that's open that I think is a good candidate to go in,
> for this release. Other than that, I don't think there's anything pending.
> However, we need to see if anyone else in the dev team has anything that
> they want to be part of this release and also see if one of us can drive the
> release.
> 
> What is the timelines for the Ubuntu distro upgrade that's being planned?

Hello,
sorry for getting back so late after end of year break.

I was asking Debian/Ubuntu people on irc as they said best would be 'end of January'. Checking projects dates:
Upcoming Ubuntu freeze: February 21st (Debian import freeze)
Upcoming Debian freeze Februrary 12th:
    2019-01-12 - Transition freeze
    2019-02-12 - Soft-freeze
    2019-03-12 - Full-freeze

Note: Their maintainers would need a bit of time also.

Checking that other MR you mentioned last time about jmod/jlink seems to have been finished in the meantime.

Any chance to get a 1.10.6 out in short?

Note: If not possible, looks they could backport it later on top of .5

13:45 < ebourg> huehner: Ant is easy to backport, if the version 1.10.6 isn't 
                in Buster we can bring it to buster-backports after the release
Comment 7 Jaikiran Pai 2019-01-22 13:31:23 UTC
> Any chance to get a 1.10.6 out in short?

I'll start a discussion on the dev list. I don't think we are waiting for any specific work to make it into this release. We just need to see if one of us is available for carrying out the release.
Comment 8 Stefan Huehner 2019-01-30 11:15:58 UTC
(In reply to Jaikiran Pai from comment #7)
> > Any chance to get a 1.10.6 out in short?
> 
> I'll start a discussion on the dev list. I don't think we are waiting for
> any specific work to make it into this release. We just need to see if one
> of us is available for carrying out the release.

Thanks for getting that on the way.

On other Note we finally got around to double check the nightly build and my colleague Javier (reporter) confirmed that latest nightly 1.10.6alpha works fine for us.