harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r642934 - in /harmony/enhanced/classlib/trunk/modules: archive/src/main/java/java/util/jar/ archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ luni/src/main/java/org/apache/harmony/luni/util/
Date Mon, 31 Mar 2008 09:08:02 GMT
Author: ayza
Date: Mon Mar 31 02:07:53 2008
New Revision: 642934

URL: http://svn.apache.org/viewvc?rev=642934&view=rev
Log:
Patches from HARMONY-5662(Non-UTF8 character in manifest error during confluence startup)
were applied.

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
      - copied, changed from r642900, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
Removed:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java?rev=642934&r1=642933&r2=642934&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
Mon Mar 31 02:07:53 2008
@@ -29,6 +29,7 @@
 import java.util.Map;
 
 import org.apache.harmony.archive.internal.nls.Messages;
+import org.apache.harmony.luni.util.InputStreamExposer;
 import org.apache.harmony.luni.util.ThreadLocalCache;
 
 /**
@@ -204,10 +205,19 @@
     public void read(InputStream is) throws IOException {
         byte[] buf;
         try {
-            buf = org.apache.harmony.luni.util.ByteBuffer.wrap(is);
+            buf = InputStreamExposer.expose(is);
         } catch (OutOfMemoryError oome) {
             throw new IOException(Messages.getString("archive.2E")); //$NON-NLS-1$
         }
+
+        // a workaround for HARMONY-5662
+        // replace EOF and NUL with another new line
+        // which does not trigger an error
+        byte b = buf[buf.length - 1];
+        if (0 == b || 26 == b) {
+            buf[buf.length - 1] = '\n';
+        }
+
         im = new InitManifest(buf, mainAttributes,
                 Attributes.Name.MANIFEST_VERSION);
         mainEnd = im.getPos();

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java?rev=642934&r1=642933&r2=642934&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
Mon Mar 31 02:07:53 2008
@@ -136,7 +136,8 @@
                 + "Name: \nSpecification-Title: foo\nSpecification-Version: 1.0\nSpecification-Vendor:
\n"
                 + "Implementation-Title: \nImplementation-Version: 1.0\nImplementation-Vendor:
\n\n";
         ByteArrayInputStream bis = new ByteArrayInputStream(manifestContent
-                .getBytes());
+                .getBytes("ISO-8859-1"));
+
 
         Manifest mf = new Manifest(bis);
         assertEquals("Should be 4 main attributes", 4, mf.getMainAttributes()
@@ -239,8 +240,33 @@
     }
 
     /**
-     * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
-     */
+     * Ensures compatibility with manifests produced by gcc.
+     * 
+     * @see <a
+     *      href="http://issues.apache.org/jira/browse/HARMONY-5662">HARMONY-5662</a>
+     */
+    public void testNul() throws IOException {
+        String manifestContent =
+                "Manifest-Version: 1.0\nCreated-By: nasty gcc tool\n\n\0";
+
+        byte[] bytes = manifestContent.getBytes("ISO-8859-1");
+        new Manifest(new ByteArrayInputStream(bytes)); // the last NUL is ok
+        
+        bytes[bytes.length - 1] = 26;
+        new Manifest(new ByteArrayInputStream(bytes)); // the last EOF is ok
+
+        bytes[bytes.length - 1] = 'A'; // the last line ignored
+        new Manifest(new ByteArrayInputStream(bytes));
+
+        bytes[2] = 0; // NUL char in Manifest
+        try {
+            new Manifest(new ByteArrayInputStream(bytes));
+            fail("IOException expected");
+        } catch (IOException e) {
+            // desired
+        }
+    }
+
     public void testDecoding() throws IOException {
         Manifest m = getManifest(ATT_JAR_NAME);
         final byte[] bVendor = new byte[] { (byte) 0xd0, (byte) 0x9C,

Copied: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
(from r642900, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java)
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java?p2=harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java&p1=harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java&r1=642900&r2=642934&rev=642934&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ByteBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
Mon Mar 31 02:07:53 2008
@@ -28,7 +28,7 @@
 /**
  * The class contains static {@link java.io.InputStream} utilities.
  */
-public class ByteBuffer {
+public class InputStreamExposer {
 
     /**
      * Provides access to a protected underlying buffer of
@@ -69,7 +69,7 @@
      *         beginning, and an end position is at the buffer end, or a copy of
      *         the underlying buffer part.
      */
-    private static byte[] wrap(ByteArrayInputStream bais) {
+    private static byte[] expose(ByteArrayInputStream bais) {
         byte[] buffer, buf;
         int pos;
         synchronized (bais) {
@@ -100,13 +100,13 @@
      *            the stream to be read.
      * @return the snapshot wrapping the buffer where the bytes are read to.
      */
-    public static byte[] wrap(InputStream is) throws IOException {
+    public static byte[] expose(InputStream is) throws IOException {
         if (is instanceof ExposedByteArrayInputStream) {
             return ((ExposedByteArrayInputStream) is).expose();
         }
 
         if (is.getClass().equals(ByteArrayInputStream.class)) {
-            return wrap((ByteArrayInputStream) is);
+            return expose((ByteArrayInputStream) is);
         }
 
         // this may be slow, put optimizations suitable for your stream



Mime
View raw message