harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r491782 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ test/java/org/apache/harmony/luni/tests/pkg1/ test/java/org/apache/harmony/luni/tests/pkg2/ test/java/tests/api/java/io/
Date Tue, 02 Jan 2007 12:20:08 GMT
Author: tellison
Date: Tue Jan  2 04:20:08 2007
New Revision: 491782

URL: http://svn.apache.org/viewvc?view=rev&rev=491782
Log:
Apply patch HARMONY-1921 ([classlib][luni] improper class replacement for the same base class
names in ObjectInputStream.resolveClass())

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java
  (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=491782&r1=491781&r2=491782
==============================================================================
--- 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
Tue Jan  2 04:20:08 2007
@@ -1305,9 +1305,22 @@
 
     private int findStreamSuperclass(Class<?> cl,
             ArrayList<ObjectStreamClass> classList, int lastIndex) {
+        ObjectStreamClass objCl;
+        String forName;
+
         for (int i = lastIndex; i < classList.size(); i++) {
-            if (cl.getName().equals(classList.get(i).getName())) {
-                return i;
+            objCl = classList.get(i);
+            forName = objCl.forClass().getName();
+
+            if (objCl.getName().equals(forName)) {
+                if (cl.getName().equals(objCl.getName())) {
+                    return i;
+                }
+            } else {
+                // there was a class replacement
+                if (cl.getName().equals(forName)) {
+                    return i;
+                }
             }
         }
         return -1;

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java?view=auto&rev=491782
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java
Tue Jan  2 04:20:08 2007
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.pkg1;
+
+import java.io.Serializable;
+
+/**
+ * Used for a serialization test, must have different package and same base name
+ * as the TestClass in o.a.h.l.tests.pkg2
+ */
+public class TestClass implements Serializable {
+    private static final long serialVersionUID = 11111L;
+
+    public int i = 0;
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg1/TestClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java?view=auto&rev=491782
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java
Tue Jan  2 04:20:08 2007
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.pkg2;
+
+import java.io.Serializable;
+
+/**
+ * Used for a serialization test, must have different package and same base name
+ * as the TestClass in o.a.h.l.tests.pkg1
+ */
+public class TestClass implements Serializable {
+    private static final long serialVersionUID = 11111L;
+    public int i = 0;
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/pkg2/TestClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=491782&r1=491781&r2=491782
==============================================================================
--- 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
Tue Jan  2 04:20:08 2007
@@ -734,9 +734,43 @@
 		public ObjectStreamClass readClassDescriptor() throws IOException,
 				ClassNotFoundException {
 			return super.readClassDescriptor();
-
 		}
 	}
+    
+    // Regression test for Harmony-1921
+    public static class ObjectInputStreamWithResolve extends ObjectInputStream {
+        public ObjectInputStreamWithResolve(InputStream in) throws IOException {
+            super(in);
+        }
+
+        protected Class resolveClass(ObjectStreamClass desc)
+                throws IOException, ClassNotFoundException {
+            if (desc.getName().equals(
+                    "org.apache.harmony.luni.tests.pkg1.TestClass")) {
+                return org.apache.harmony.luni.tests.pkg2.TestClass.class;
+            }
+            return super.resolveClass(desc);
+        }
+    }
+
+    public void test_resolveClass() throws Exception {
+        org.apache.harmony.luni.tests.pkg1.TestClass to1 = new org.apache.harmony.luni.tests.pkg1.TestClass();
+        to1.i = 555;
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(to1);
+        oos.flush();
+        byte[] bytes = baos.toByteArray();
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        ObjectInputStream ois = new ObjectInputStreamWithResolve(bais);
+        org.apache.harmony.luni.tests.pkg2.TestClass to2 = (org.apache.harmony.luni.tests.pkg2.TestClass)
ois
+                .readObject();
+
+        if (to2.i != to1.i) {
+            fail("Wrong object read. Expected val: " + to1.i + ", got: "
+                    + to2.i);
+        }
+    }
 	
 	public void test_readClassDescriptor() throws IOException,
 			ClassNotFoundException {



Mime
View raw message