4 Replies Latest reply on Dec 4, 2006 12:00 PM by roy.russo

    upload zip archive bug : NegativeArraySizeException

    antoine_h

      when uploading an archive file, there is an exception :

      java.lang.NegativeArraySizeException
       at org.jboss.portal.cms.impl.jcr.command.StoreArchiveCommand.execute(StoreArchiveCommand.java:72)
       at org.jboss.portal.cms.impl.jcr.JCRCommand.dispatch(JCRCommand.java:61)

      It is because of the zipEntry.getSize() that return -1 (unknown size).
      this is because of the use of ZipInputStream class.
      there is a turnaround with using the ZipFile class instead.
      see : http://forum.java.sun.com/thread.jspa?threadID=492219&messageID=2316626

      I have opened a jira for this.

        • 1. Re: upload zip archive bug : NegativeArraySizeException
          antoine_h
          • 2. Re: upload zip archive bug : NegativeArraySizeException

            I dont think the workaround will help here, because whats being passed in is the inputstream from the fileupload. The zipfile class expects a File, so am not sure yet on how to deal with this, but it seems like a definite "bug" that needs to be fixed.

            • 3. Re: upload zip archive bug : NegativeArraySizeException
              antoine_h

              I am working on this right now.
              yes, I've seen it is a bit more complicated...

              I have tried it this way :

              FileItem item = (FileItem) itr.next();
              ZipFile zipFile = new ZipFile(item.getName());

              in the CMSAdminPortlet code (a copy of it).
              and it seems to work.

              the FileItem javadoc says getName() is not reliable.

              it is working with : Internet Explorer 6 and windows XP.
              but not working with opera 8.5. getName() return only the file name, not the base path.

              I don't know how to solve this.
              may be searching in the zip api (which I don't know that much).

              is there a way to store a file temporarily in the jboss temp folder (or some other places). then reopen it with ZipFile ?



              • 4. Re: upload zip archive bug : NegativeArraySizeException

                I've spent the better part of today playing with this, and researching it... There doesnt seem to be a resolution, just that java's zipinputstream cant read non-standard zips.

                This is actually a pretty good site and info: http://mindprod.com/jgloss/zip.html Of course...

                The following code won't work if ZipOutputStream was used to create the zip file. ZipEntry.getSize will return -1.


                So even thought you can change things to use a tempFile and use ZipFile, you still have to do:

                while (entries.hasMoreElements())
                 {
                 zipEntry = (ZipEntry)entries.nextElement();
                 String itemName = zipEntry.getName();
                 if (!zipEntry.isDirectory())
                 {
                 long fileSize = zipEntry.getSize();
                


                Its the only way to read the file items, is to getSize, but if it returns -1, then we die again. So even using zipFile wont work.

                I'll attach the changed I made to the jira, but for now, am adding some exception handling, as I dont see a workaround at all here.