harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r532239 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ test/java/tests/api/java/io/ test/resources/tests/api/java/io/
Date Wed, 25 Apr 2007 07:49:19 GMT
Author: pyang
Date: Wed Apr 25 00:49:17 2007
New Revision: 532239

URL: http://svn.apache.org/viewvc?view=rev&rev=532239
Log:
Apply patch for HARMONY-3726([classlib][luni]java.io.ObjectInputStream fails to parse serialization
file with [L[Ljava.lang.String;; as ObjectStreamField signature for string array.)

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_integers.ser
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_strings.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?view=diff&rev=532239&r1=532238&r2=532239
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Wed Apr 25 00:49:17 2007
@@ -971,9 +971,37 @@
                     enableResolve = old;
                 }
             }
+            
+            classSig = formatClassSig(classSig);
             ObjectStreamField f = new ObjectStreamField(classSig, fieldName);
             fields[i] = f;
         }
+    }
+    
+    /*
+     * Format the class signature for ObjectStreamField, for example,
+     * "[L[Ljava.lang.String;;" is converted to "[Ljava.lang.String;"
+     */
+    private static String formatClassSig(String classSig) {
+        int start = 0;
+        int end = classSig.length();
+
+        if (end <= 0) {
+            return classSig;
+        }
+
+        while (classSig.startsWith("[L", start)
+                && classSig.charAt(end - 1) == ';') {
+            start += 2;
+            end--;
+        }
+
+        if (start > 0) {
+            start -= 2;
+            end++;
+            return classSig.substring(start, end);
+        }
+        return classSig;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=532239&r1=532238&r2=532239
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Wed Apr 25 00:49:17 2007
@@ -38,6 +38,7 @@
 import java.util.Hashtable;
 import java.util.Vector;
 
+import org.apache.harmony.luni.tests.java.lang.ClassTest;
 import org.apache.harmony.testframework.serialization.SerializationTest;
 import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
 
@@ -932,7 +933,24 @@
             // expected
         }
     }
-
+    
+    //Regression Test for HARMONY-3726
+    public void test_readObject_array() throws Exception {
+        
+        final String resourcePrefix = ObjectInputStreamTest.class.getPackage().getName().replace('.',
'/');
+        
+        ObjectInputStream oin = new ObjectInputStream(this.getClass().getClassLoader().getResourceAsStream(
+                resourcePrefix+"/test_array_strings.ser"));               
+        TestArray testArray = (TestArray) oin.readObject();
+        String[] strings = new String[] { "AAA", "BBB" };
+        assertTrue(java.util.Arrays.equals(strings, testArray.array));
+
+        oin = new ObjectInputStream(this.getClass().getClassLoader().getResourceAsStream(
+                resourcePrefix+"/test_array_integers.ser"));        
+        testArray = (TestArray) oin.readObject();
+        Integer[] integers = new Integer[] { 10, 20 };
+        assertTrue(java.util.Arrays.equals(integers, testArray.array));
+    }
 
     /**
      * Sets up the fixture, for example, open a network connection. This method
@@ -944,6 +962,17 @@
     }
 }
 
+class TestArray implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+    
+    public Object[] array;
+    
+    public TestArray(Object[] array) {
+        this.array = array;
+    }
+    
+}
 
 class Test implements Serializable {
 	private static final long serialVersionUID = 1L;

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_integers.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_integers.ser?view=auto&rev=532239
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_integers.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_strings.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_strings.ser?view=auto&rev=532239
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/io/test_array_strings.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message