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

ZipException when deflating and running garbage collection

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.1.6_002
    • 1.1.3
    • core-libs
    • b02
    • x86
    • windows_nt



        Name: joT67522 Date: 01/09/98


        (1) Run the enclosed test program under WindowsNT.
        (2) Watch the threads get
        java.util.zip.ZipException: invalid stored block lengths
        until only one thread is running.

        ------------------------------------
        import java.util.zip.Deflater;
        import java.util.zip.DeflaterOutputStream;
        import java.io.ByteArrayOutputStream;
        import java.util.zip.Inflater;
        import java.util.zip.InflaterInputStream;
        import java.io.ByteArrayInputStream;
        import java.io.IOException;
        import java.util.Date;

        public class ZipEx {

        public static void main(String[] args) throws IOException{
        Object locker = new Object();
        for (int i=0; i<10; i++) {
        ZipThread t = new ZipThread(i, locker);
        t.start();
        }
        }
        }


        class ZipThread extends Thread {
        private int myNumber;
        Object myLocker;

        ZipThread(int n, Object locker) {
        super("ZipThread "+n);
        myNumber = n;
        myLocker = locker;
        }

        public void run() {
        int i = 0;
        Date start = new Date();
        System.out.println("Starting ["+myNumber+"] at " + start);
        try {
        byte[] data = new byte[256];

        for (; i<2000000; i++) {
        byte[] output;
        ByteArrayOutputStream baos;
        Deflater deflater;
        DeflaterOutputStream deflaterOS;
        baos = new ByteArrayOutputStream();
        deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
        deflaterOS = new DeflaterOutputStream(baos, deflater);

        // Following synchronize needed to avoid:
        // ZipException: invalid stored block lengths
        //synchronized(myLocker) {
        deflaterOS.write(data);
        deflaterOS.close();
        output = baos.toByteArray();
        //}
        ByteArrayInputStream bais = new ByteArrayInputStream(output);
        Inflater inflater = new Inflater(true);
        InflaterInputStream inflaterIS = new InflaterInputStream(bais, inflater);
        byte[] input = new byte[data.length];
        int off = 0;
        for (;off<input.length;) {
        int read = inflaterIS.read(input, off, input.length-off);
        if (-1 == read) break;
        off += read;
        }
        for (int j=0; j<input.length; j++) {
        if (data[j] != input[j]) {
        throw new Error("["+myNumber+"]data mismatch");
        }
        }
        inflater.end();
        // Following synchronize needed to avoid:
        // ZipException: invalid stored block lengths
        //synchronized(myLocker) {
        System.gc();
        System.runFinalization();
        System.gc();
        //}
        }

        } catch(OutOfMemoryError e) {
        Date now = new Date();
        System.out.println("\n["+myNumber+"]Out of memory at " + now + " i=" + i);
        throw e;
        } catch(IOException e) {
        Date now = new Date();
        System.out.println("\n["+myNumber+"]I/O Exception at " + now + " i=" + i);
        e.printStackTrace();
        }
        Date end = new Date();
        System.out.println("End ["+myNumber+"] at " + end + " i=" + i);
        }
        }
        (Review ID: 22735)
        ======================================================================

              zlisunw Zhenghua Li (Inactive)
              johsunw Joon Oh (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: