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

BCEL: Utility.encode forget to close

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b01
    • Resolved In Build:
      b29
    • CPU:
      x86_64
    • OS:
      os_x

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        all version

        A DESCRIPTION OF THE PROBLEM :
        old Version in com/sun/org/apache/bcel/internal/classfile/Utility.java
        new Version in java.xml/com/sun/org/apache/bcel/internal/classfile/Utility.java

        function `public static String encode(byte[] bytes, boolean compress) throws IOException {`
        if compress is true.
        after jdk jdk1.8.0_251
        code is
        ```
        if (compress) {
                    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            GZIPOutputStream gos = new GZIPOutputStream(baos)) {
                        gos.write(bytes, 0, bytes.length);
                        bytes = baos.toByteArray();
                    }
                }
        ```
        gos forget to close,and `bytes = baos.toByteArray();` doesn't work .

        so if I called encode and parament compress is true after jdk1.8.0_251,In doesn't work


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        String classname = Utility.encode(bytecode,true); and

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        real compressed BCEL code
        ACTUAL -
        result always $l$8b$I$A$A$A$A$A$A$A

        ---------- BEGIN SOURCE ----------
        if (compress) {
                    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            GZIPOutputStream gos = new GZIPOutputStream(baos)) {
                        gos.write(bytes, 0, bytes.length);
                        gos.close();
                        bytes = baos.toByteArray();
                    }
                }
        ---------- END SOURCE ----------

        FREQUENCY : always


          Attachments

          1. Capture_8u241.JPG
            Capture_8u241.JPG
            104 kB
          2. Capture_8u251.JPG
            Capture_8u251.JPG
            46 kB
          3. Main.java
            2 kB

            Issue Links

              Activity

                People

                Assignee:
                joehw Joe Wang
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: