Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8020687

Deflater.setLevel does not work as expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 6, 7
    • core-libs
    • b108
    • windows_7
    • Verified

      FULL PRODUCT VERSION :
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows Version 6.1.7601


      A DESCRIPTION OF THE PROBLEM :
      Deflater.setLevel() does not seem to set the compression level. Worse than a mere NOOP, if one calls deflater.setLevel() with an argument different that the already set by the constructor (explicitly or implicitly), the deflate stops working as expected.

      Tested also with 1.6.0_07-b06 in Linux.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      level in constructor: len=8 [120, -38, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
      level via setLevel(): len=8 [120, -38, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

      ACTUAL -
      level in constructor: len=8 [120, -38, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
      level via setLevel(): len=0 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Arrays;
      import java.util.zip.Deflater;

      public class TestDeflater {

      public static void test1 () throws Exception {
               byte[] output = new byte[16];
               Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION);
               compresser.finish();
               int len = compresser.deflate(output);
               System.out.println( " level in constructor: len= " + len+ " " +Arrays.toString(output));
          }
          public static void test2 () throws Exception {
               byte[] output = new byte[16];
               Deflater compresser = new Deflater();
               compresser.setLevel(Deflater.BEST_COMPRESSION);
               compresser.setInput( " blah " .getBytes( " UTF-8 " ));
               compresser.finish();
               int len = compresser.deflate(output);
               System.out.println( " level via setLevel(): len= " + len+ " " +Arrays.toString(output));
          }
          public static void main (String[] args) throws java.lang.Exception
          {
                  test1();
                  test2();
          }
      }
      ---------- END SOURCE ----------

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: