harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r520935 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/ test/java/org/apache/harmony/archive/tests/java/util/jar/
Date Wed, 21 Mar 2007 16:17:52 GMT
Author: ayza
Date: Wed Mar 21 09:17:51 2007
New Revision: 520935

URL: http://svn.apache.org/viewvc?view=rev&rev=520935
Log:
Applying patch from HARMONY-3424 ([classlib][archive]java.util.jar.JarEntry fails to get certificate
while another instance jarEntry of the same jarFile has readed all the data of the same entry)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java?view=diff&rev=520935&r1=520934&r2=520935
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
Wed Mar 21 09:17:51 2007
@@ -34,15 +34,13 @@
     private Attributes attributes;
 
     JarFile parentJar;
-
-    Certificate certificates[];
-
+   
     CodeSigner signers[];
 
     // Cached factory used to build CertPath-s in <code>getCodeSigners()</code>.
     private CertificateFactory factory;
 
-    private boolean isFactoryChecked = false;
+    private boolean isFactoryChecked = false;     
 
     /**
      * Create a new JarEntry named name
@@ -90,12 +88,14 @@
      * @return java.security.cert.Certificate[] Certificates for this entry
      */
     public Certificate[] getCertificates() {
-        if (certificates == null) {
+        if (null == parentJar) {
+            return null;
+        }
+        JarVerifier jarVerifier = parentJar.verifier;
+        if (null == jarVerifier) {
             return null;
         }
-        Certificate[] copy = new Certificate[certificates.length];
-        System.arraycopy(certificates, 0, copy, 0, copy.length);
-        return copy;
+        return jarVerifier.getCertificates(getName());
     }
 
     void setAttributes(Attributes attrib) {
@@ -111,10 +111,8 @@
     public JarEntry(JarEntry je) {
         super(je);
         parentJar = je.parentJar;
-        attributes = je.attributes;
-        certificates = je.certificates;
+        attributes = je.attributes;        
         signers = je.signers;
-
     }
 
     /**
@@ -127,8 +125,7 @@
      */
     public CodeSigner[] getCodeSigners() {
         if (null == signers) {
-            signers = getCodeSigners(certificates);
-
+            signers = getCodeSigners(getCertificates());
         }
         if (null == signers) {
             return null;

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java?view=diff&rev=520935&r1=520934&r2=520935
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
Wed Mar 21 09:17:51 2007
@@ -232,10 +232,7 @@
 
             public JarEntry nextElement() {
                 JarEntry je = new JarEntry(ze.nextElement());
-                je.parentJar = jf;
-                if (verifier != null) {
-                    je.certificates = verifier.getCertificates(je.getName());
-                }
+                je.parentJar = jf;                
                 return je;
             }
         }
@@ -376,10 +373,7 @@
             return ze;
         }
         JarEntry je = new JarEntry(ze);
-        je.parentJar = this;
-        if (verifier != null) {
-            je.certificates = verifier.getCertificates(je.getName());
-        }
+        je.parentJar = this;        
         return je;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java?view=diff&rev=520935&r1=520934&r2=520935
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
Wed Mar 21 09:17:51 2007
@@ -386,9 +386,6 @@
                     JarFile.MANIFEST_NAME, zipEntry.getName(), jarName }));
         }
         verifiedEntries.put(zipEntry.getName(), entry.certificates);
-        if (zipEntry instanceof JarEntry) {
-            ((JarEntry) zipEntry).certificates = entry.certificates.clone();
-        }
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java?view=diff&rev=520935&r1=520934&r2=520935
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
Wed Mar 21 09:17:51 2007
@@ -108,10 +108,24 @@
     /**
      * @tests java.util.jar.JarEntry#getCertificates()
      */
-    public void test_getCertificates() {
+    public void test_getCertificates() throws Exception{
         zipEntry = jarFile.getEntry(entryName2);
         jarEntry = new JarEntry(zipEntry);
         assertNull("Shouldn't have any Certificates", jarEntry.getCertificates());
+        
+        //Regression Test for HARMONY-3424
+        String jarFileName = "TestCodeSigners.jar";
+        Support_Resources.copyFile(resources, null, jarFileName);
+        File file = new File(resources, jarFileName);
+        JarFile jarFile = new JarFile(file);
+        JarEntry jarEntry1 = jarFile.getJarEntry("Test.class");
+        JarEntry jarEntry2 = jarFile.getJarEntry("Test.class");
+        InputStream in = jarFile.getInputStream(jarEntry1);
+        byte[] buffer = new byte[1024];
+         while(in.read(buffer)>=0);
+        in.close();
+        assertNotNull(jarEntry1.getCertificates());
+        assertNotNull(jarEntry2.getCertificates());
     }
 
     /**



Mime
View raw message