Bug 63457 - Error using ant-1.10.6 with jdk8
Summary: Error using ant-1.10.6 with jdk8
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.10.6
Hardware: PC All
: P1 blocker (vote)
Target Milestone: 1.10.7
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-22 07:21 UTC by David Pérez Serrada
Modified: 2019-06-01 08:37 UTC (History)
1 user (show)



Attachments
Sample Source Code (876 bytes, text/plain)
2019-05-22 07:55 UTC, David Pérez Serrada
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Pérez Serrada 2019-05-22 07:21:39 UTC
Although ant-1.10.6.jar is compiled with jdk8 compatibility is not possible to run it with a jdk 8 Runtime.

If you run with a jdk8 runtime you would get the following error:

Caused by: java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;
                at org.apache.tools.zip.Simple8BitZipEncoding.encode(Simple8BitZipEncoding.java:250)
                at org.apache.tools.zip.ZipOutputStream.getName(ZipOutputStream.java:1646)
                at org.apache.tools.zip.ZipOutputStream.writeLocalFileHeader(ZipOutputStream.java:1059)
                at org.apache.tools.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:769)


Run with jdk11 runtime works without problem. Seems like a linking problem for me.

Version 1.10.5 works perfect using both jdk8 and jdk11 runtimes.
Comment 1 Jaikiran Pai 2019-05-22 07:24:59 UTC
That doesn't look good. Is there a build file that you can attach to help reproduce this?
Comment 2 David Pérez Serrada 2019-05-22 07:55:12 UTC
Created attachment 36594 [details]
Sample Source Code

Simple and ugly code showing the problem.

--------------------------------------------------------------------------------
dperez@pc-dperezs /cygdrive/d/temp
$ /cygdrive/d/java/jdks/jdk1.8.0_171/bin/javac -cp ant-1.10.6.jar ZipTest.java

dperez@pc-dperezs /cygdrive/d/temp
$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

dperez@pc-dperezs /cygdrive/d/temp
$ java -cp "ant-1.10.6.jar;." ZipTest
Begin
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;
        at org.apache.tools.zip.NioZipEncoding.encode(NioZipEncoding.java:105)
        at org.apache.tools.zip.ZipOutputStream.getName(ZipOutputStream.java:1646)
        at org.apache.tools.zip.ZipOutputStream.writeLocalFileHeader(ZipOutputStream.java:1059)
        at org.apache.tools.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:769)
        at ZipTest.main(ZipTest.java:18)

dperez@pc-dperezs /cygdrive/d/temp
$ java -cp "ant-1.10.5.jar;." ZipTest
Begin
End

dperez@pc-dperezs /cygdrive/d/temp
$ java -cp "ant-1.10.6.jar;." ZipTest^C

dperez@pc-dperezs /cygdrive/d/temp
$ . setjava11.sh

dperez@pc-dperezs /cygdrive/d/temp
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

dperez@pc-dperezs /cygdrive/d/temp
$ java -cp "ant-1.10.6.jar;." ZipTest
Begin
End
--------------------------------------------------------------------------------
Comment 3 David Pérez Serrada 2019-05-22 07:56:14 UTC
Is important the setEncoding part:

		// Fails if set this encoding 
		zout.setEncoding("ISO-8859-1");
		// With this encoding works perfect
		// zout.setEncoding("UTF-8");
Comment 4 Jaikiran Pai 2019-05-22 07:58:24 UTC
Thanks for those details. I can confirm, based on what I see in the generated class files for the Ant library, that there's a difference in what bytecode is generated for this class (even with -target set to 1.8). I have to understand a bit about the --release option in javac to see if we (or rather me) missed adding that option to our build process when releasing this 1.10.6 version.

I'll take a more detailed look at this tonight.
Comment 5 Jaikiran Pai 2019-05-24 01:55:09 UTC
I've had a look at this one in more detail and I understand where we went wrong with our build and release process, that introduced this issue. I am in the process of fixing this and this obviously will need a new release. I'll be sending out the details to the dev list once I have a potential fix.
Comment 6 J.M. (Martijn) Kruithof 2019-06-01 08:37:42 UTC
Reproduced by building on jdk11 and running the ant testset using jdk8.
Should be fixed by:
https://github.com/apache/ant/commit/823a5316eb69f49d72838c24ded4478ecf29b970