Java Inflater will loop infinitely sometimesIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?How do I convert a String to an int in Java?Creating a memory leak with Java

What does "in official capacity" mean?

Verb Classification of あげる (to give)

What language is Raven using for her attack in the new 52?

Why tantalum for the Hayabusa bullets?

How to foreshadow to avoid a 'deus ex machina'-construction

If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?

How to innovate in OR

On the sensitivity conjecture?

May a hotel provide accommodation for fewer people than booked?

Move arrows along a contour

Microgravity indicators

Applications of pure mathematics in operations research

Embedded C - Most elegant way to insert a delay

Circle symbol compatible with square and triangle

Is it possible for a particle to decay via gravity?

Would people understand me speaking German all over Europe?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

Should I put my name first, or last in the team members list

How can flights operated by the same company have such different prices when marketed by another?

How do you deal with characters with multiple races?

"Valet parking " or "parking valet"

Can living where Earth magnet ore is abundent provide any protection?

What is the highest achievable score in Catan

What are the closest international airports in different countries?



Java Inflater will loop infinitely sometimes


Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?How do I convert a String to an int in Java?Creating a memory leak with Java






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In my application, I'm trying to compress/decompress byte array using java's Inflater/Deflater class.
Here's part of the code I used at first:



 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); 
byte[] buffer = new byte[1024];
while (!inflater.finished())
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);



Then after I deployed the code it'll randomly (very rare) cause the whole application hang, and when I took a thread dump, I can identify that one thread hanging



 at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:259)
- locked java.util.zip.ZStreamRef@fc71443
at java.util.zip.Inflater.inflate(Inflater.java:280)


It doesn't happen very often. Then I googled everywhere and found out it could be some empty byte data passed in the inflater and finished() will never return true.



So I used a workaround, instead of using



while (!inflater.finished()) 


to determine if it's finished, I used



while (inflater.getRemaining() > 0)


But it happened again.
Now it makes me wonder what's the real reason that causes the issue. There shouldn't be any empty array passed in the inflater, even if it did, how come getRemaining() method did not break the while loop?
Can anybody help pls? It's really bugging me.










share|improve this question



















  • 1





    How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

    – Erwin Bolwidt
    Mar 26 at 21:30











  • Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

    – Yiwei
    Mar 27 at 12:20

















0















In my application, I'm trying to compress/decompress byte array using java's Inflater/Deflater class.
Here's part of the code I used at first:



 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); 
byte[] buffer = new byte[1024];
while (!inflater.finished())
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);



Then after I deployed the code it'll randomly (very rare) cause the whole application hang, and when I took a thread dump, I can identify that one thread hanging



 at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:259)
- locked java.util.zip.ZStreamRef@fc71443
at java.util.zip.Inflater.inflate(Inflater.java:280)


It doesn't happen very often. Then I googled everywhere and found out it could be some empty byte data passed in the inflater and finished() will never return true.



So I used a workaround, instead of using



while (!inflater.finished()) 


to determine if it's finished, I used



while (inflater.getRemaining() > 0)


But it happened again.
Now it makes me wonder what's the real reason that causes the issue. There shouldn't be any empty array passed in the inflater, even if it did, how come getRemaining() method did not break the while loop?
Can anybody help pls? It's really bugging me.










share|improve this question



















  • 1





    How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

    – Erwin Bolwidt
    Mar 26 at 21:30











  • Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

    – Yiwei
    Mar 27 at 12:20













0












0








0








In my application, I'm trying to compress/decompress byte array using java's Inflater/Deflater class.
Here's part of the code I used at first:



 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); 
byte[] buffer = new byte[1024];
while (!inflater.finished())
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);



Then after I deployed the code it'll randomly (very rare) cause the whole application hang, and when I took a thread dump, I can identify that one thread hanging



 at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:259)
- locked java.util.zip.ZStreamRef@fc71443
at java.util.zip.Inflater.inflate(Inflater.java:280)


It doesn't happen very often. Then I googled everywhere and found out it could be some empty byte data passed in the inflater and finished() will never return true.



So I used a workaround, instead of using



while (!inflater.finished()) 


to determine if it's finished, I used



while (inflater.getRemaining() > 0)


But it happened again.
Now it makes me wonder what's the real reason that causes the issue. There shouldn't be any empty array passed in the inflater, even if it did, how come getRemaining() method did not break the while loop?
Can anybody help pls? It's really bugging me.










share|improve this question














In my application, I'm trying to compress/decompress byte array using java's Inflater/Deflater class.
Here's part of the code I used at first:



 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); 
byte[] buffer = new byte[1024];
while (!inflater.finished())
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);



Then after I deployed the code it'll randomly (very rare) cause the whole application hang, and when I took a thread dump, I can identify that one thread hanging



 at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:259)
- locked java.util.zip.ZStreamRef@fc71443
at java.util.zip.Inflater.inflate(Inflater.java:280)


It doesn't happen very often. Then I googled everywhere and found out it could be some empty byte data passed in the inflater and finished() will never return true.



So I used a workaround, instead of using



while (!inflater.finished()) 


to determine if it's finished, I used



while (inflater.getRemaining() > 0)


But it happened again.
Now it makes me wonder what's the real reason that causes the issue. There shouldn't be any empty array passed in the inflater, even if it did, how come getRemaining() method did not break the while loop?
Can anybody help pls? It's really bugging me.







java compression






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 21:22









YiweiYiwei

247 bronze badges




247 bronze badges










  • 1





    How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

    – Erwin Bolwidt
    Mar 26 at 21:30











  • Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

    – Yiwei
    Mar 27 at 12:20












  • 1





    How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

    – Erwin Bolwidt
    Mar 26 at 21:30











  • Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

    – Yiwei
    Mar 27 at 12:20







1




1





How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

– Erwin Bolwidt
Mar 26 at 21:30





How did you determine that there is an "infinite loop"? Just because a method is very busy (probably because you're giving it lots of data) doesn't mean it's in an infinite loop. It's very unlikely that there is such a serious bug as you claim in one of the most widely used classes in Java (since very compressed jar file is decompressed with it)

– Erwin Bolwidt
Mar 26 at 21:30













Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

– Yiwei
Mar 27 at 12:20





Cause the whole application froze for more than 5 minutes, and the thread dump always shows the thread doing inflate(), and that thread is blocking other threads. Also, the data needs decompressing definitely takes less than 10 seconds.

– Yiwei
Mar 27 at 12:20












2 Answers
2






active

oldest

votes


















1














Confused by the same problem, I find this page.



This is my workaround for this, it may helps:



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (!inflater.finished())
int i = inflater.inflate(buffer);
if (i == 0)
break;

byteArrayOutputStream.write(buffer, 0, i);






share|improve this answer
































    0














    The javadoc of inflate:




    Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.




    So @Wildo Luo was certainly right to check for 0 being returned.



    byte[] buffer = new byte[1024]; 
    while (!inflater.finished())
    int count = inflater.inflate(buffer);
    if (count != 0 )
    outputStream.write(buffer, 0, count);
    else
    if (inflater.needsInput()) // Not everything read
    inflater.setInput(...);
    else if (inflater.needsDictionary()) // Dictionary to be loaded
    inflater.setDictionary(...);



    inflater.end();


    I can only imagine that elsewhere the code is not entirely right, maybe on the compression size. Better first check the general code. There is the Inflater(boolean nowrap) requiring an extra byte, the end() call. Exception handling (try-finally). Etcetera.



    For unkown data, unknown occurrences: using a try-catch, find compressed data to check whether it is a data based error, and for testing any solution.






    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%2f55366393%2fjava-inflater-will-loop-infinitely-sometimes%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Confused by the same problem, I find this page.



      This is my workaround for this, it may helps:



      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      byte[] buffer = new byte[1024];
      while (!inflater.finished())
      int i = inflater.inflate(buffer);
      if (i == 0)
      break;

      byteArrayOutputStream.write(buffer, 0, i);






      share|improve this answer





























        1














        Confused by the same problem, I find this page.



        This is my workaround for this, it may helps:



        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        while (!inflater.finished())
        int i = inflater.inflate(buffer);
        if (i == 0)
        break;

        byteArrayOutputStream.write(buffer, 0, i);






        share|improve this answer



























          1












          1








          1







          Confused by the same problem, I find this page.



          This is my workaround for this, it may helps:



          ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
          byte[] buffer = new byte[1024];
          while (!inflater.finished())
          int i = inflater.inflate(buffer);
          if (i == 0)
          break;

          byteArrayOutputStream.write(buffer, 0, i);






          share|improve this answer













          Confused by the same problem, I find this page.



          This is my workaround for this, it may helps:



          ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
          byte[] buffer = new byte[1024];
          while (!inflater.finished())
          int i = inflater.inflate(buffer);
          if (i == 0)
          break;

          byteArrayOutputStream.write(buffer, 0, i);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 29 at 7:35









          Wilde LuoWilde Luo

          112 bronze badges




          112 bronze badges


























              0














              The javadoc of inflate:




              Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.




              So @Wildo Luo was certainly right to check for 0 being returned.



              byte[] buffer = new byte[1024]; 
              while (!inflater.finished())
              int count = inflater.inflate(buffer);
              if (count != 0 )
              outputStream.write(buffer, 0, count);
              else
              if (inflater.needsInput()) // Not everything read
              inflater.setInput(...);
              else if (inflater.needsDictionary()) // Dictionary to be loaded
              inflater.setDictionary(...);



              inflater.end();


              I can only imagine that elsewhere the code is not entirely right, maybe on the compression size. Better first check the general code. There is the Inflater(boolean nowrap) requiring an extra byte, the end() call. Exception handling (try-finally). Etcetera.



              For unkown data, unknown occurrences: using a try-catch, find compressed data to check whether it is a data based error, and for testing any solution.






              share|improve this answer





























                0














                The javadoc of inflate:




                Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.




                So @Wildo Luo was certainly right to check for 0 being returned.



                byte[] buffer = new byte[1024]; 
                while (!inflater.finished())
                int count = inflater.inflate(buffer);
                if (count != 0 )
                outputStream.write(buffer, 0, count);
                else
                if (inflater.needsInput()) // Not everything read
                inflater.setInput(...);
                else if (inflater.needsDictionary()) // Dictionary to be loaded
                inflater.setDictionary(...);



                inflater.end();


                I can only imagine that elsewhere the code is not entirely right, maybe on the compression size. Better first check the general code. There is the Inflater(boolean nowrap) requiring an extra byte, the end() call. Exception handling (try-finally). Etcetera.



                For unkown data, unknown occurrences: using a try-catch, find compressed data to check whether it is a data based error, and for testing any solution.






                share|improve this answer



























                  0












                  0








                  0







                  The javadoc of inflate:




                  Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.




                  So @Wildo Luo was certainly right to check for 0 being returned.



                  byte[] buffer = new byte[1024]; 
                  while (!inflater.finished())
                  int count = inflater.inflate(buffer);
                  if (count != 0 )
                  outputStream.write(buffer, 0, count);
                  else
                  if (inflater.needsInput()) // Not everything read
                  inflater.setInput(...);
                  else if (inflater.needsDictionary()) // Dictionary to be loaded
                  inflater.setDictionary(...);



                  inflater.end();


                  I can only imagine that elsewhere the code is not entirely right, maybe on the compression size. Better first check the general code. There is the Inflater(boolean nowrap) requiring an extra byte, the end() call. Exception handling (try-finally). Etcetera.



                  For unkown data, unknown occurrences: using a try-catch, find compressed data to check whether it is a data based error, and for testing any solution.






                  share|improve this answer













                  The javadoc of inflate:




                  Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed. A return value of 0 indicates that needsInput() or needsDictionary() should be called in order to determine if more input data or a preset dictionary is required. In the latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.




                  So @Wildo Luo was certainly right to check for 0 being returned.



                  byte[] buffer = new byte[1024]; 
                  while (!inflater.finished())
                  int count = inflater.inflate(buffer);
                  if (count != 0 )
                  outputStream.write(buffer, 0, count);
                  else
                  if (inflater.needsInput()) // Not everything read
                  inflater.setInput(...);
                  else if (inflater.needsDictionary()) // Dictionary to be loaded
                  inflater.setDictionary(...);



                  inflater.end();


                  I can only imagine that elsewhere the code is not entirely right, maybe on the compression size. Better first check the general code. There is the Inflater(boolean nowrap) requiring an extra byte, the end() call. Exception handling (try-finally). Etcetera.



                  For unkown data, unknown occurrences: using a try-catch, find compressed data to check whether it is a data based error, and for testing any solution.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 29 at 7:59









                  Joop EggenJoop Eggen

                  82.1k7 gold badges59 silver badges110 bronze badges




                  82.1k7 gold badges59 silver badges110 bronze badges






























                      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%2f55366393%2fjava-inflater-will-loop-infinitely-sometimes%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현