Getting “negative time” exception when unpacking zip file with zip4j










0















I'm using zip4j to extract zip files. For many users this works fine but a Windows 8 user is getting the following exception:



net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.lang.IllegalArgumentException: Negative time
at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:163)
at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
...


Negative time seems to be caused by a file on the file system having a negative time and/or by a JVM bug. Does anyone know how to fix this problem since this is quite odd and not related to my usage of the API I assume.



zip4j hasn't been maintained since 2013 so I wouldn't be surprised if it has some bugs but there just isn't another more capable zip library without boilerplate besides the JDK one. However, I need password protected zip file support and that isn't supported by the JDK.



Installing JDK 11 and using it to run the application does not fix the problem but it was worth a try.










share|improve this question




























    0















    I'm using zip4j to extract zip files. For many users this works fine but a Windows 8 user is getting the following exception:



    net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.lang.IllegalArgumentException: Negative time
    at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:163)
    at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
    at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
    at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
    at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
    ...


    Negative time seems to be caused by a file on the file system having a negative time and/or by a JVM bug. Does anyone know how to fix this problem since this is quite odd and not related to my usage of the API I assume.



    zip4j hasn't been maintained since 2013 so I wouldn't be surprised if it has some bugs but there just isn't another more capable zip library without boilerplate besides the JDK one. However, I need password protected zip file support and that isn't supported by the JDK.



    Installing JDK 11 and using it to run the application does not fix the problem but it was worth a try.










    share|improve this question


























      0












      0








      0








      I'm using zip4j to extract zip files. For many users this works fine but a Windows 8 user is getting the following exception:



      net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.lang.IllegalArgumentException: Negative time
      at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:163)
      at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
      at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
      at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
      at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
      ...


      Negative time seems to be caused by a file on the file system having a negative time and/or by a JVM bug. Does anyone know how to fix this problem since this is quite odd and not related to my usage of the API I assume.



      zip4j hasn't been maintained since 2013 so I wouldn't be surprised if it has some bugs but there just isn't another more capable zip library without boilerplate besides the JDK one. However, I need password protected zip file support and that isn't supported by the JDK.



      Installing JDK 11 and using it to run the application does not fix the problem but it was worth a try.










      share|improve this question
















      I'm using zip4j to extract zip files. For many users this works fine but a Windows 8 user is getting the following exception:



      net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: java.lang.IllegalArgumentException: Negative time
      at net.lingala.zip4j.unzip.Unzip.initExtractFile(Unzip.java:163)
      at net.lingala.zip4j.unzip.Unzip.initExtractAll(Unzip.java:83)
      at net.lingala.zip4j.unzip.Unzip.extractAll(Unzip.java:73)
      at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:488)
      at net.lingala.zip4j.core.ZipFile.extractAll(ZipFile.java:451)
      ...


      Negative time seems to be caused by a file on the file system having a negative time and/or by a JVM bug. Does anyone know how to fix this problem since this is quite odd and not related to my usage of the API I assume.



      zip4j hasn't been maintained since 2013 so I wouldn't be surprised if it has some bugs but there just isn't another more capable zip library without boilerplate besides the JDK one. However, I need password protected zip file support and that isn't supported by the JDK.



      Installing JDK 11 and using it to run the application does not fix the problem but it was worth a try.







      java zip zip4j






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 12:40







      BullyWiiPlaza

















      asked Nov 12 '18 at 12:06









      BullyWiiPlazaBullyWiiPlaza

      5,96334656




      5,96334656






















          1 Answer
          1






          active

          oldest

          votes


















          0














          After doing some more research, I found 7-Zip-JBinding:



          <dependency>
          <groupId>net.sf.sevenzipjbinding</groupId>
          <artifactId>sevenzipjbinding</artifactId>
          <version>LATEST</version>
          </dependency>
          <dependency>
          <groupId>net.sf.sevenzipjbinding</groupId>
          <artifactId>sevenzipjbinding-all-platforms</artifactId>
          <version>LATEST</version>
          </dependency>


          The following code can be used to extract a password protected zip file:



          public static void unzipUsing7Zip(String zipFilePath,
          String destinationDirectory,
          String password) throws IOException

          try (val randomAccessFile = new RandomAccessFile(zipFilePath, "r");
          val randomAccessFileInStream = new RandomAccessFileInStream(randomAccessFile);
          val inArchive = openInArchive(null, randomAccessFileInStream))

          val simpleInArchive = inArchive.getSimpleInterface();
          val archiveItems = simpleInArchive.getArchiveItems();

          for (val archiveItem : archiveItems)

          if (!archiveItem.isFolder())

          val archiveItemPath = archiveItem.getPath();
          val targetFilePath = destinationDirectory + separator + archiveItemPath;

          try (val fileOutputStream = new FileOutputStream(targetFilePath))

          archiveItem.extractSlow(data ->

          try

          if (archiveItemPath.indexOf(separator) > 0)

          // Create parent folder(s)
          val lastSeparatorIndex = archiveItemPath.lastIndexOf(separator);
          val path = destinationDirectory + separator + archiveItemPath.substring(0, lastSeparatorIndex);
          createDirectories(Paths.get(path));


          fileOutputStream.write(data);
          catch (Exception exception)

          exception.printStackTrace();


          return data.length;
          , password);







          Based on here but cleaned up and real file extraction code via FileOutputStream added.



          Additional note: val comes from lombok of course.



          <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>LATEST</version>
          <scope>provided</scope>
          </dependency>





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261849%2fgetting-negative-time-exception-when-unpacking-zip-file-with-zip4j%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After doing some more research, I found 7-Zip-JBinding:



            <dependency>
            <groupId>net.sf.sevenzipjbinding</groupId>
            <artifactId>sevenzipjbinding</artifactId>
            <version>LATEST</version>
            </dependency>
            <dependency>
            <groupId>net.sf.sevenzipjbinding</groupId>
            <artifactId>sevenzipjbinding-all-platforms</artifactId>
            <version>LATEST</version>
            </dependency>


            The following code can be used to extract a password protected zip file:



            public static void unzipUsing7Zip(String zipFilePath,
            String destinationDirectory,
            String password) throws IOException

            try (val randomAccessFile = new RandomAccessFile(zipFilePath, "r");
            val randomAccessFileInStream = new RandomAccessFileInStream(randomAccessFile);
            val inArchive = openInArchive(null, randomAccessFileInStream))

            val simpleInArchive = inArchive.getSimpleInterface();
            val archiveItems = simpleInArchive.getArchiveItems();

            for (val archiveItem : archiveItems)

            if (!archiveItem.isFolder())

            val archiveItemPath = archiveItem.getPath();
            val targetFilePath = destinationDirectory + separator + archiveItemPath;

            try (val fileOutputStream = new FileOutputStream(targetFilePath))

            archiveItem.extractSlow(data ->

            try

            if (archiveItemPath.indexOf(separator) > 0)

            // Create parent folder(s)
            val lastSeparatorIndex = archiveItemPath.lastIndexOf(separator);
            val path = destinationDirectory + separator + archiveItemPath.substring(0, lastSeparatorIndex);
            createDirectories(Paths.get(path));


            fileOutputStream.write(data);
            catch (Exception exception)

            exception.printStackTrace();


            return data.length;
            , password);







            Based on here but cleaned up and real file extraction code via FileOutputStream added.



            Additional note: val comes from lombok of course.



            <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>LATEST</version>
            <scope>provided</scope>
            </dependency>





            share|improve this answer



























              0














              After doing some more research, I found 7-Zip-JBinding:



              <dependency>
              <groupId>net.sf.sevenzipjbinding</groupId>
              <artifactId>sevenzipjbinding</artifactId>
              <version>LATEST</version>
              </dependency>
              <dependency>
              <groupId>net.sf.sevenzipjbinding</groupId>
              <artifactId>sevenzipjbinding-all-platforms</artifactId>
              <version>LATEST</version>
              </dependency>


              The following code can be used to extract a password protected zip file:



              public static void unzipUsing7Zip(String zipFilePath,
              String destinationDirectory,
              String password) throws IOException

              try (val randomAccessFile = new RandomAccessFile(zipFilePath, "r");
              val randomAccessFileInStream = new RandomAccessFileInStream(randomAccessFile);
              val inArchive = openInArchive(null, randomAccessFileInStream))

              val simpleInArchive = inArchive.getSimpleInterface();
              val archiveItems = simpleInArchive.getArchiveItems();

              for (val archiveItem : archiveItems)

              if (!archiveItem.isFolder())

              val archiveItemPath = archiveItem.getPath();
              val targetFilePath = destinationDirectory + separator + archiveItemPath;

              try (val fileOutputStream = new FileOutputStream(targetFilePath))

              archiveItem.extractSlow(data ->

              try

              if (archiveItemPath.indexOf(separator) > 0)

              // Create parent folder(s)
              val lastSeparatorIndex = archiveItemPath.lastIndexOf(separator);
              val path = destinationDirectory + separator + archiveItemPath.substring(0, lastSeparatorIndex);
              createDirectories(Paths.get(path));


              fileOutputStream.write(data);
              catch (Exception exception)

              exception.printStackTrace();


              return data.length;
              , password);







              Based on here but cleaned up and real file extraction code via FileOutputStream added.



              Additional note: val comes from lombok of course.



              <dependency>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
              <version>LATEST</version>
              <scope>provided</scope>
              </dependency>





              share|improve this answer

























                0












                0








                0







                After doing some more research, I found 7-Zip-JBinding:



                <dependency>
                <groupId>net.sf.sevenzipjbinding</groupId>
                <artifactId>sevenzipjbinding</artifactId>
                <version>LATEST</version>
                </dependency>
                <dependency>
                <groupId>net.sf.sevenzipjbinding</groupId>
                <artifactId>sevenzipjbinding-all-platforms</artifactId>
                <version>LATEST</version>
                </dependency>


                The following code can be used to extract a password protected zip file:



                public static void unzipUsing7Zip(String zipFilePath,
                String destinationDirectory,
                String password) throws IOException

                try (val randomAccessFile = new RandomAccessFile(zipFilePath, "r");
                val randomAccessFileInStream = new RandomAccessFileInStream(randomAccessFile);
                val inArchive = openInArchive(null, randomAccessFileInStream))

                val simpleInArchive = inArchive.getSimpleInterface();
                val archiveItems = simpleInArchive.getArchiveItems();

                for (val archiveItem : archiveItems)

                if (!archiveItem.isFolder())

                val archiveItemPath = archiveItem.getPath();
                val targetFilePath = destinationDirectory + separator + archiveItemPath;

                try (val fileOutputStream = new FileOutputStream(targetFilePath))

                archiveItem.extractSlow(data ->

                try

                if (archiveItemPath.indexOf(separator) > 0)

                // Create parent folder(s)
                val lastSeparatorIndex = archiveItemPath.lastIndexOf(separator);
                val path = destinationDirectory + separator + archiveItemPath.substring(0, lastSeparatorIndex);
                createDirectories(Paths.get(path));


                fileOutputStream.write(data);
                catch (Exception exception)

                exception.printStackTrace();


                return data.length;
                , password);







                Based on here but cleaned up and real file extraction code via FileOutputStream added.



                Additional note: val comes from lombok of course.



                <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>LATEST</version>
                <scope>provided</scope>
                </dependency>





                share|improve this answer













                After doing some more research, I found 7-Zip-JBinding:



                <dependency>
                <groupId>net.sf.sevenzipjbinding</groupId>
                <artifactId>sevenzipjbinding</artifactId>
                <version>LATEST</version>
                </dependency>
                <dependency>
                <groupId>net.sf.sevenzipjbinding</groupId>
                <artifactId>sevenzipjbinding-all-platforms</artifactId>
                <version>LATEST</version>
                </dependency>


                The following code can be used to extract a password protected zip file:



                public static void unzipUsing7Zip(String zipFilePath,
                String destinationDirectory,
                String password) throws IOException

                try (val randomAccessFile = new RandomAccessFile(zipFilePath, "r");
                val randomAccessFileInStream = new RandomAccessFileInStream(randomAccessFile);
                val inArchive = openInArchive(null, randomAccessFileInStream))

                val simpleInArchive = inArchive.getSimpleInterface();
                val archiveItems = simpleInArchive.getArchiveItems();

                for (val archiveItem : archiveItems)

                if (!archiveItem.isFolder())

                val archiveItemPath = archiveItem.getPath();
                val targetFilePath = destinationDirectory + separator + archiveItemPath;

                try (val fileOutputStream = new FileOutputStream(targetFilePath))

                archiveItem.extractSlow(data ->

                try

                if (archiveItemPath.indexOf(separator) > 0)

                // Create parent folder(s)
                val lastSeparatorIndex = archiveItemPath.lastIndexOf(separator);
                val path = destinationDirectory + separator + archiveItemPath.substring(0, lastSeparatorIndex);
                createDirectories(Paths.get(path));


                fileOutputStream.write(data);
                catch (Exception exception)

                exception.printStackTrace();


                return data.length;
                , password);







                Based on here but cleaned up and real file extraction code via FileOutputStream added.



                Additional note: val comes from lombok of course.



                <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>LATEST</version>
                <scope>provided</scope>
                </dependency>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 '18 at 14:41









                BullyWiiPlazaBullyWiiPlaza

                5,96334656




                5,96334656



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261849%2fgetting-negative-time-exception-when-unpacking-zip-file-with-zip4j%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20