You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Anton Ivanov (JIRA)" <ji...@apache.org> on 2006/12/04 15:12:21 UTC

[jira] Created: (HARMONY-2436) Reading from a closed Jar file is allowed

Reading from a closed Jar file is allowed
-----------------------------------------

                 Key: HARMONY-2436
                 URL: http://issues.apache.org/jira/browse/HARMONY-2436
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Anton Ivanov
            Priority: Minor


Reading from InputStream which was opened on some JarFile
is allowed even if this JarFile was closed .

java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
via getInputStream() method will be closed. But JarFile behaves in a different manner.

Code to reproduce this problem:

import java.util.jar.*;
import java.io.*;
public class TestJarFileClose{

    public static void main(String[] args) {
        byte[] b = new byte[1024];
        try {
            JarFile jf = new JarFile("hello_world.jar");
            InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
            jf.close();
            int r = is.read(b, 0, 1024);
            System.out.println("Test failed, readed from closed JAR file: "+r);
            is.close();
        } catch (Exception e) {
            System.out.println("Test passed: "+e);    
        } 
    }
}

Output on RI:  
Test passed: java.lang.IllegalStateException: zip file closed

Output on Harmony: 
Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Re: [jira] Commented: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by Alexei Zakharov <al...@gmail.com>.
I agree that it is ok just to throw exception if JAR/ZIP file is
closed. IMO RI's behavior is too complex to follow.

Regards,

2007/6/13, Tony Wu <wu...@gmail.com>:
> Ok, If no one objects, I'd like to provider a new patch for 2436 and
> create another JIRA to record this non-bug difference, since the old
> one is outdated.
>
> On 6/11/07, Tim Ellison <t....@gmail.com> wrote:
> > Tony Wu wrote:
> > > Hi,
> > > Seems RI cached some bytes, which can be read even if the jarfile has
> > > been closed. I wonder what's your opinion about that? should we follow
> > > RI to cache the bytes and should we use the buffer size the same as
> > > RI?
> >
> > Sounds like a bug in the RI to me.  If the JAR is closed I would not
> > expect to be able to read from it.  I suggest closing as a non-bug
> > difference.
> >
> > Regards,
> > Tim
> >
> --
> Tony Wu
> China Software Development Lab, IBM


-- 
Alexei Zakharov,
Intel ESSD

Re: [jira] Commented: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by Tony Wu <wu...@gmail.com>.
Ok, If no one objects, I'd like to provider a new patch for 2436 and
create another JIRA to record this non-bug difference, since the old
one is outdated.

On 6/11/07, Tim Ellison <t....@gmail.com> wrote:
> Tony Wu wrote:
> > Hi,
> > Seems RI cached some bytes, which can be read even if the jarfile has
> > been closed. I wonder what's your opinion about that? should we follow
> > RI to cache the bytes and should we use the buffer size the same as
> > RI?
>
> Sounds like a bug in the RI to me.  If the JAR is closed I would not
> expect to be able to read from it.  I suggest closing as a non-bug
> difference.
>
> Regards,
> Tim
>


-- 
Tony Wu
China Software Development Lab, IBM

Re: [jira] Commented: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by Tim Ellison <t....@gmail.com>.
Tony Wu wrote:
> Hi,
> Seems RI cached some bytes, which can be read even if the jarfile has
> been closed. I wonder what's your opinion about that? should we follow
> RI to cache the bytes and should we use the buffer size the same as
> RI?

Sounds like a bug in the RI to me.  If the JAR is closed I would not
expect to be able to read from it.  I suggest closing as a non-bug
difference.

Regards,
Tim

Re: [jira] Commented: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by Tony Wu <wu...@gmail.com>.
Hi,
Seems RI cached some bytes, which can be read even if the jarfile has
been closed. I wonder what's your opinion about that? should we follow
RI to cache the bytes and should we use the buffer size the same as
RI?

On 5/30/07, Alexei Zakharov (JIRA) <ji...@apache.org> wrote:
>
>    [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12500084 ]
>
> Alexei Zakharov commented on HARMONY-2436:
> ------------------------------------------
>
> Hi Tony, thanks for the patch. But it looks like RI's behavior is more tricky indeed. Try to look at the following test:
>
> === TestJarFileClose.java:
> import java.util.jar.*;
> import java.io.*;
>
> public class TestJarFileClose{
>
>    public static void main(String[] args) {
>        byte[] b = new byte[4];
>        int cnt = 0;
>
>        try {
>            JarFile jf = new JarFile("ecj_3.3M7.jar");
>            InputStream is = jf.getInputStream(jf.getEntry(
>                    "org/eclipse/jdt/internal/compiler/ClassFile.class"));
>            int r;
>
>            // attention! fill the internal buffer?
>            if (System.getProperty("initial.read") != null) {
>                r = is.read(b, 0, 4);
>            }
>
>            jf.close();
>
>            while (true) {
>                r = is.read(b, 0, 1);
>
>                if (r != -1)  {
>                   cnt += r;
>                } else {
>                   break;
>                }
>            }
>            is.close();
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>        System.out.println("Bytes red after file closure: " + cnt);
>    }
> }
> ===
>
> CMD: java TestJarFileClose
> OUTPUT:
> java.util.zip.ZipException: ZipFile closed
>        at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:524)
>        at java.util.zip.ZipFile.access$1400(ZipFile.java:35)
>        at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:556)
>        at java.util.zip.ZipFile$2.fill(ZipFile.java:338)
>        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
>        at TestJarFileClose.main(TestJarFileClose.java:24)
> Bytes red after file closure: 0
>
> CMD: java -Dinitial.read TestJarFileClose
> OUTPUT:
> java.util.zip.ZipException: ZipFile closed
>        at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:524)
>        at java.util.zip.ZipFile.access$1400(ZipFile.java:35)
>        at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:556)
>        at java.util.zip.ZipFile$2.fill(ZipFile.java:338)
>        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
>        at TestJarFileClose.main(TestJarFileClose.java:24)
> Bytes red after file closure: 24968
>
> To run this test you need to put "ecj_3.3M7.jar" in the directory where the test class is located. The test shows that RI maintains some internal buffer and if this buffer is initialized and filled by reading some data from stream then ZipException is thrown only after reading 24968 bytes - probably after the buffer is exhausted and new read attempt is performed. AFAIU current Harmony implementation tries to allocate enough bytes to keep complete ZipEntry in memory without using any fixed-size buffer - see Java_java_util_zip_ZipFile_inflateEntryImpl2() in the file "zip.c".
>
> I am not sure if we should try to refactor our code to completely follow RI here. It can appear to be a non-trivial fix.
>
> > [classlib][archive] Reading from a closed Jar file is allowed
> > -------------------------------------------------------------
> >
> >                 Key: HARMONY-2436
> >                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
> >             Project: Harmony
> >          Issue Type: Bug
> >          Components: Classlib
> >            Reporter: Anton Ivanov
> >            Assignee: Alexei Zakharov
> >            Priority: Minor
> >         Attachments: harmony-2436.diff, hello_world.jar
> >
> >
> > Reading from InputStream which was opened on some JarFile
> > is allowed even if this JarFile was closed .
> > java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> > specification of this method ensure that if JarFile is closed all InputStreams that were obtained
> > via getInputStream() method will be closed. But JarFile behaves in a different manner.
> > Code to reproduce this problem:
> > import java.util.jar.*;
> > import java.io.*;
> > public class TestJarFileClose{
> >     public static void main(String[] args) {
> >         byte[] b = new byte[1024];
> >         try {
> >             JarFile jf = new JarFile("hello_world.jar");
> >             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
> >             jf.close();
> >             int r = is.read(b, 0, 1024);
> >             System.out.println("Test failed, readed from closed JAR file: "+r);
> >             is.close();
> >         } catch (Exception e) {
> >             System.out.println("Test passed: "+e);
> >         }
> >     }
> > }
> > Output on RI:
> > Test passed: java.lang.IllegalStateException: zip file closed
> > Output on Harmony:
> > Test failed, readed from closed JAR file: 427
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>


-- 
Tony Wu
China Software Development Lab, IBM

[jira] Assigned: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Alexei Zakharov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexei Zakharov reassigned HARMONY-2436:
----------------------------------------

    Assignee: Alexei Zakharov

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Assignee: Alexei Zakharov
>            Priority: Minor
>         Attachments: harmony-2436.diff, hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Tony Wu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tony Wu updated HARMONY-2436:
-----------------------------

    Attachment: harmony-2436.diff

patch available, would you pls try it? Thanks

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>         Attachments: harmony-2436.diff, hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Alexei Zakharov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexei Zakharov updated HARMONY-2436:
-------------------------------------

    Patch Info: [Patch Available]

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>         Attachments: harmony-2436.diff, hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Alexei Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12500084 ] 

Alexei Zakharov commented on HARMONY-2436:
------------------------------------------

Hi Tony, thanks for the patch. But it looks like RI's behavior is more tricky indeed. Try to look at the following test:

=== TestJarFileClose.java:
import java.util.jar.*;
import java.io.*;

public class TestJarFileClose{

    public static void main(String[] args) {
        byte[] b = new byte[4];
        int cnt = 0;

        try {
            JarFile jf = new JarFile("ecj_3.3M7.jar");
            InputStream is = jf.getInputStream(jf.getEntry(
                    "org/eclipse/jdt/internal/compiler/ClassFile.class"));
            int r;

            // attention! fill the internal buffer?
            if (System.getProperty("initial.read") != null) {
                r = is.read(b, 0, 4);
            }

            jf.close();

            while (true) {
                r = is.read(b, 0, 1);

                if (r != -1)  {
                   cnt += r;
                } else {
                   break;
                }
            }
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Bytes red after file closure: " + cnt);
    }
}
===

CMD: java TestJarFileClose
OUTPUT:
java.util.zip.ZipException: ZipFile closed
        at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:524)
        at java.util.zip.ZipFile.access$1400(ZipFile.java:35)
        at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:556)
        at java.util.zip.ZipFile$2.fill(ZipFile.java:338)
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
        at TestJarFileClose.main(TestJarFileClose.java:24)
Bytes red after file closure: 0

CMD: java -Dinitial.read TestJarFileClose
OUTPUT:
java.util.zip.ZipException: ZipFile closed
        at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:524)
        at java.util.zip.ZipFile.access$1400(ZipFile.java:35)
        at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:556)
        at java.util.zip.ZipFile$2.fill(ZipFile.java:338)
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:134)
        at TestJarFileClose.main(TestJarFileClose.java:24)
Bytes red after file closure: 24968

To run this test you need to put "ecj_3.3M7.jar" in the directory where the test class is located. The test shows that RI maintains some internal buffer and if this buffer is initialized and filled by reading some data from stream then ZipException is thrown only after reading 24968 bytes - probably after the buffer is exhausted and new read attempt is performed. AFAIU current Harmony implementation tries to allocate enough bytes to keep complete ZipEntry in memory without using any fixed-size buffer - see Java_java_util_zip_ZipFile_inflateEntryImpl2() in the file "zip.c". 

I am not sure if we should try to refactor our code to completely follow RI here. It can appear to be a non-trivial fix.

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Assignee: Alexei Zakharov
>            Priority: Minor
>         Attachments: harmony-2436.diff, hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Tony Wu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-2436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tony Wu updated HARMONY-2436:
-----------------------------

    Attachment: harmony-2436-2.diff

post new patch since the old one is outdated.

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Assignee: Alexei Zakharov
>            Priority: Minor
>         Attachments: harmony-2436-2.diff, harmony-2436.diff, hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-2436) Reading from a closed Jar file is allowed

Posted by "Anton Ivanov (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2436?page=all ]

Anton Ivanov updated HARMONY-2436:
----------------------------------

    Attachment: hello_world.jar

To run the code above to reproduce this issue put hello_world.jar from the attachment to the current directory.

> Reading from a closed Jar file is allowed
> -----------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>         Attachments: hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (HARMONY-2436) [classlib][archive] Reading from a closed Jar file is allowed

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2436?page=all ]

Paulex Yang updated HARMONY-2436:
---------------------------------

    Summary: [classlib][archive] Reading from a closed Jar file is allowed  (was: Reading from a closed Jar file is allowed)

> [classlib][archive] Reading from a closed Jar file is allowed
> -------------------------------------------------------------
>
>                 Key: HARMONY-2436
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2436
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>         Attachments: hello_world.jar
>
>
> Reading from InputStream which was opened on some JarFile
> is allowed even if this JarFile was closed .
> java.util.jar.JarFile inherits close() method from java.util.zip.ZipFile and
> specification of this method ensure that if JarFile is closed all InputStreams that were obtained 
> via getInputStream() method will be closed. But JarFile behaves in a different manner.
> Code to reproduce this problem:
> import java.util.jar.*;
> import java.io.*;
> public class TestJarFileClose{
>     public static void main(String[] args) {
>         byte[] b = new byte[1024];
>         try {
>             JarFile jf = new JarFile("hello_world.jar");
>             InputStream is = jf.getInputStream(jf.getEntry("hello_world/HelloWorld.class"));
>             jf.close();
>             int r = is.read(b, 0, 1024);
>             System.out.println("Test failed, readed from closed JAR file: "+r);
>             is.close();
>         } catch (Exception e) {
>             System.out.println("Test passed: "+e);    
>         } 
>     }
> }
> Output on RI:  
> Test passed: java.lang.IllegalStateException: zip file closed
> Output on Harmony: 
> Test failed, readed from closed JAR file: 427 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira