Bug 54967 - NullPointerException when updating a zip file that has duplicate entries
Summary: NullPointerException when updating a zip file that has duplicate entries
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.9.1
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: 1.9.2
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-14 12:51 UTC by Alex Russell
Modified: 2013-12-31 14:54 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Russell 2013-05-14 12:51:35 UTC
When updating an existing zip file that has duplicate entries, the zip task throws a NullPointerException.  This simple script reproduces the problem:

<?xml version="1.0"?>
<project name="testzip" default="testzip">

    <target name="testzip">
        <delete dir="testfiles"/>
        <delete file="test.zip"/>
        <mkdir dir="testfiles"/>
        <echo file="testfiles/test.txt">This is a test file</echo>
        <zip destfile="test.zip" basedir="testfiles">
            <fileset dir="testfiles"/>
        </zip>
        <zip destfile="test.zip" update="true">
            <fileset dir="${basedir}" includes="build.xml"/>
        </zip>
    </target>

</project>


Output:

Buildfile: /home/arussell/dev/testzip/build.xml

testzip:
   [delete] Deleting directory /home/arussell/dev/testzip/testfiles
   [delete] Deleting: /home/arussell/dev/testzip/test.zip
    [mkdir] Created dir: /home/arussell/dev/testzip/testfiles
      [zip] Building zip: /home/arussell/dev/testzip/test.zip
      [zip] Updating zip: /home/arussell/dev/testzip/test.zip

BUILD FAILED
/home/arussell/dev/testzip/build.xml:12: java.lang.NullPointerException
	at org.apache.tools.ant.taskdefs.Zip.zipFile(Zip.java:1827)
	at org.apache.tools.ant.taskdefs.Zip.zipFile(Zip.java:1856)
	at org.apache.tools.ant.taskdefs.Zip.addResource(Zip.java:1031)
	at org.apache.tools.ant.taskdefs.Zip.addResources(Zip.java:953)
	at org.apache.tools.ant.taskdefs.Zip.executeMain(Zip.java:702)
	at org.apache.tools.ant.taskdefs.Zip.execute(Zip.java:568)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:435)
	at org.apache.tools.ant.Target.performTasks(Target.java:456)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
	at org.apache.tools.ant.Main.runBuild(Main.java:851)
	at org.apache.tools.ant.Main.startAnt(Main.java:235)
	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds


After a bit of digging, it seems that that this problem is related to the Zip64 support added in Ant 1.9.0.  When I built a version of Ant with zip64Mode in ZipOutputStream set to Zip64Mode.Never the problem went away.

It seems that the ZipEntry.equals method is concluding that objects are different when they should be the same.  This is down to the values of the extra fields being different.

Anyway, I have only found this to cause a problem in build scripts that are erroneously adding duplicate entries to zip files so adding 'duplicate="preserve"' is the simple workaround.

Thanks
Comment 1 Stefan Bodewig 2013-05-15 04:35:02 UTC
I can confirm the bug.  The problem seems to be ZipFile.getInputStream returning null when asked for the stream of a duplicate entry.  Off the top of my head I don't know a quick fix since ZipFile hashes entries by name - I'm looking into it.
Comment 2 Stefan Bodewig 2013-05-20 15:26:35 UTC
Just a quick status update: https://issues.apache.org/jira/browse/COMPRESS-227

A quick fix is to simply ignore existing duplicate entries, everything that tried to preserve all duplicates will need an API change to ZipFile.  I'll discuss the options on the dev list.
Comment 3 Stefan Bodewig 2013-12-31 14:54:38 UTC
the NPE itself has been fixed in Ant 1.9.2