ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Earl Hood <earlh...@gmail.com>
Subject ZipOutputStream exception in Ant 1.9.5 and 1.9.6
Date Mon, 20 Jul 2015 20:56:42 GMT
It appears the zip problems have not been fully fixed in Ant.

I have a program that uses Ant's ZipOutputStream class, and it has had
no problems with versions of Ant 1.9.4 and earlier.  However, with Ant
1.9.5 and 1.9.6, I get the following exception:

  java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.apache.tools.zip.ZipOutputStream.createCentralFileHeader(ZipOutputStream.java:1264)
    at org.apache.tools.zip.ZipOutputStream.createCentralFileHeader(ZipOutputStream.java:1178)
    at org.apache.tools.zip.ZipOutputStream.writeCentralDirectoryInChunks(ZipOutputStream.java:513)
    at org.apache.tools.zip.ZipOutputStream.finish(ZipOutputStream.java:498)
    at org.apache.tools.zip.ZipOutputStream.close(ZipOutputStream.java:940)
    at com.pbmassoc.nsiv.util.ZipDMs.zipFlattenDMs(ZipDMs.java:102)
    at com.pbmassoc.nsiv.util.ZipDMs.main(ZipDMs.java:174)
    ...snip...


The following is the code block that uses ZipOutputStream.  There are
some application-specific calls in it, but I figure they are fairly
easy to understand what they do:

  public static void zipFlattenDMs(
      File outZip,
      File dir
  ) throws IOException {
    List<File> files = NSIVUtil.getDMFiles(dir);
    ZipOutputStream out = null;
    try {
      // We use apache tools (Ant) ZipOutputStream.
      out = new ZipOutputStream(outZip);
      out.setLevel(9);
      for (File f : files) {
        String basename = f.getName();
        if (!FileUtil.isXml(basename) ||
            (!basename.startsWith(DMC_PREFIX) &&
             !basename.startsWith(DME_PREFIX))) {
          continue;
        }
        String dmcBase   = S1000DUtil.extractDMCBase(basename);
        String entryName = dmcBase + ".xml";
        ZipEntry e       = new ZipEntry(entryName);
        e.setComment(basename);
        e.setTime(f.lastModified());
        out.putNextEntry(e);
        NSIVUtil.sendFile(f, out);
        out.closeEntry();
      }
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }


Exception is thrown when calling the close() method on `out' in the
finally block.

As a test, I modified the above code to use Java's version of
ZipOutputStream, and I received no errors.  The change is basically
modifying the constructor call as follows:

      out = new ZipOutputStream(new FileOutputStream(outZip));

And importing Java's classes and not Ant's (this includes using Java's
ZipEntry classs).

I may be able to live with using the Java library implementation of the
zip classes, but it does raise some concerns about the robustness of the
Ant's zip-related tasks, which we use in various Ant build files.  The
testing I have performed with our project has shown no other problems.

I am guessing the following work noted in the release notes:

 * ported some of the write-optimization of Commons Compress 1.10 to
   the ZIP package

introduced regression bugs, bugs that have not been fully flushed out,
or detected.

Any guidance appreciated,

--ewh

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message