harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r520358 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/ main/java/org/apache/harmony/luni/util/ test/java/tests/api/java/net/
Date Tue, 20 Mar 2007 11:18:26 GMT
Author: pyang
Date: Tue Mar 20 04:18:25 2007
New Revision: 520358

URL: http://svn.apache.org/viewvc?view=rev&rev=520358
Log:
Apply patch for HARMONY-3436 ([classlib][luni]java.net.JarURLConnection gets different jarFile
when the inputstream has been closed if cache is not used.)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java?view=diff&rev=520358&r1=520357&r2=520358
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
Tue Mar 20 04:18:25 2007
@@ -61,6 +61,8 @@
     private JarFile jarFile;
 
     private JarEntry jarEntry;
+    
+    private boolean closed;
 
     ReferenceQueue<JarFile> cacheQueue = new ReferenceQueue<JarFile>();
 
@@ -335,6 +337,9 @@
      */
     @Override
     public InputStream getInputStream() throws IOException {
+        if (closed) {
+            throw new IllegalStateException(Msg.getString("KA027"));
+        }
         if (!connected) {
             connect();
         }
@@ -469,7 +474,7 @@
         public void close() throws IOException {
             super.close();
             if (!useCaches) {
-                connected = false;
+                closed = true;
                 jarFile.close();
             }
         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?view=diff&rev=520358&r1=520357&r2=520358
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
Tue Mar 20 04:18:25 2007
@@ -319,3 +319,4 @@
 KA024=One of urls is null
 KA025=Method has not been implemented
 KA026=JAR entry {0} not found in {1}
+KA027=Inputstream of the JarURLConnection has been closed

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java?view=diff&rev=520358&r1=520357&r2=520358
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
Tue Mar 20 04:18:25 2007
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -147,6 +148,35 @@
                 + jarFile.getAbsolutePath().replaceAll(" ", "%20") + "!/")
                 .openConnection();
         conn.getJarFile().entries();
+    }
+    
+    //Regression for HARMONY-3436
+    public void test_setUseCaches() throws Exception {
+        File resources = Support_Resources.createTempFolder();
+        Support_Resources.copyFile(resources, null, "hyts_att.jar");
+        File file = new File(resources.toString() + "/hyts_att.jar");
+        URL url = new URL("jar:file:" + file.getPath() + "!/HasAttributes.txt");
+
+        JarURLConnection connection = (JarURLConnection) url.openConnection();
+        connection.setUseCaches(false);
+        InputStream in = connection.getInputStream();
+        JarFile jarFile1 = connection.getJarFile();
+        JarEntry jarEntry1 = connection.getJarEntry();
+        byte[] data = new byte[1024];
+        while (in.read(data) >= 0)
+            ;
+        in.close();
+        JarFile jarFile2 = connection.getJarFile();
+        JarEntry jarEntry2 = connection.getJarEntry();
+        assertSame(jarFile1, jarFile2);
+        assertSame(jarEntry1, jarEntry2);
+        
+        try {
+            connection.getInputStream();
+            fail("should throw IllegalStateException");
+        } catch (IllegalStateException e) {
+            // expected
+        }
     }
 
 	/**



Mime
View raw message